File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
project_euler/problem_073 Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 1818
1919from math import gcd
2020
21+
2122def slow_solution (max_d : int = 12_000 ) -> int :
2223 """
2324 Returns number of fractions lie between 1/3 and 1/2 in the sorted set
@@ -40,6 +41,7 @@ def slow_solution(max_d: int = 12_000) -> int:
4041 fractions_number += 1
4142 return fractions_number
4243
44+
4345def solution (max_d : int = 12_000 ) -> int :
4446 """
4547 Returns number of fractions lie between 1/3 and 1/2 in the sorted set
@@ -58,10 +60,7 @@ def solution(max_d: int = 12_000) -> int:
5860 fractions_number = 0
5961 for d in range (max_d + 1 ):
6062 if d % 2 == 0 :
61- if (d // 3 + 1 ) % 2 == 0 :
62- n_start = d // 3 + 2
63- else :
64- n_start = d // 3 + 1
63+ n_start = d // 3 + 2 if (d // 3 + 1 ) % 2 == 0 else d // 3 + 1
6564 for n in range (n_start , (d + 1 ) // 2 , 2 ):
6665 if gcd (n , d ) == 1 :
6766 fractions_number += 1
@@ -71,6 +70,7 @@ def solution(max_d: int = 12_000) -> int:
7170 fractions_number += 1
7271 return fractions_number
7372
73+
7474def benchmark () -> None :
7575 """
7676 Benchmarks
@@ -86,6 +86,7 @@ def benchmark() -> None:
8686 print (f"slow_solution : { timeit ('slow_solution()' , globals = globals (), number = 10 )} " )
8787 print (f"solution : { timeit ('solution()' , globals = globals (), number = 10 )} " )
8888
89+
8990if __name__ == "__main__" :
9091 print (f"{ solution () = } " )
9192 benchmark ()
You can’t perform that action at this time.
0 commit comments