File tree 1 file changed +39
-0
lines changed
project_euler/problem_231
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Project Euler Problem 231: https://projecteuler.net/problem=231
3
+
4
+ The binomial coefficient choose(10, 3)=120.
5
+ 120 = 2^3 * 3 * 5 = 2 * 2 * 2 * 3 * 5, and 2 + 2 + 2 + 3 + 5 = 14.
6
+ So the sum of the terms in the prime factorisation of choose(10, 3) is 14.
7
+
8
+ Find the sum of the terms in the prime factorisation of choose(20_000_000, 15_000_000).
9
+ """
10
+
11
+ from sympy import factorint
12
+ from collections import Counter
13
+
14
+
15
+ def solution (n : int = 20_000_000 , k : int = 15_000_000 ) -> int :
16
+ """
17
+ Returns the sum of all the multiples of 3 or 5 below n.
18
+
19
+ >>> solution(10, 3)
20
+ 14
21
+ """
22
+
23
+ a , b = 20_000_000 , 15_000_000
24
+ top , bot = [], []
25
+ for t in range (b + 1 , a + 1 ):
26
+ top .extend (factorint (t , multiple = True ))
27
+ for b in range (1 , a - b + 1 ):
28
+ bot .extend (factorint (b , multiple = True ))
29
+
30
+ top = Counter (top )
31
+ bot = Counter (bot )
32
+ s = 0
33
+ for k , v in top .items ():
34
+ s += k * (v - bot [k ])
35
+ return s
36
+
37
+
38
+ if __name__ == "__main__" :
39
+ print (f"{ solution () = } " )
You can’t perform that action at this time.
0 commit comments