File tree 3 files changed +57
-0
lines changed
project_euler/problem_078
3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 788
788
* [ Sol1] ( https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_076/sol1.py )
789
789
* Problem 077
790
790
* [ Sol1] ( https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_077/sol1.py )
791
+ * Problem 078
792
+ * [ Sol1] ( https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_078/sol1.py )
791
793
* Problem 080
792
794
* [ Sol1] ( https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_080/sol1.py )
793
795
* Problem 081
Original file line number Diff line number Diff line change
1
+ """
2
+ Problem 78
3
+ Url: https://projecteuler.net/problem=78
4
+ Statement:
5
+ Let p(n) represent the number of different ways in which n coins
6
+ can be separated into piles. For example, five coins can be separated
7
+ into piles in exactly seven different ways, so p(5)=7.
8
+
9
+ OOOOO
10
+ OOOO O
11
+ OOO OO
12
+ OOO O O
13
+ OO OO O
14
+ OO O O O
15
+ O O O O O
16
+ Find the least value of n for which p(n) is divisible by one million.
17
+ """
18
+
19
+ import itertools
20
+
21
+
22
+ def solution (number : int = 1000000 ) -> int :
23
+ """
24
+ >>> solution()
25
+ 55374
26
+ """
27
+ partitions = [1 ]
28
+
29
+ for i in itertools .count (len (partitions )):
30
+ item = 0
31
+ for j in itertools .count (1 ):
32
+ sign = - 1 if j % 2 == 0 else + 1
33
+ index = (j * j * 3 - j ) // 2
34
+ if index > i :
35
+ break
36
+ item += partitions [i - index ] * sign
37
+ index += j
38
+ if index > i :
39
+ break
40
+ item += partitions [i - index ] * sign
41
+ item %= number
42
+
43
+ if item == 0 :
44
+ return i
45
+ partitions .append (item )
46
+
47
+ return 0
48
+
49
+
50
+ if __name__ == "__main__" :
51
+ import doctest
52
+
53
+ doctest .testmod ()
54
+
55
+ print (f"{ solution () = } " )
You can’t perform that action at this time.
0 commit comments