Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 488f143

Browse files
RamanaMendapre-commit-ci[bot]MaximSmolskiy
authored
Performance: 25% faster Project Euler 73 #10503 (#11553)
* Seperate slow_solution and solution * Add performance benchmark * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix issues * Update sol1.py * Update sol1.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 5c50572 commit 488f143

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎project_euler/problem_073/sol1.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ def solution(max_d: int = 12_000) -> int:
3636

3737
fractions_number = 0
3838
for d in range(max_d + 1):
39-
for n in range(d // 3 + 1, (d + 1) // 2):
39+
n_start = d // 3 + 1
40+
n_step = 1
41+
if d % 2 == 0:
42+
n_start += 1 - n_start % 2
43+
n_step = 2
44+
for n in range(n_start, (d + 1) // 2, n_step):
4045
if gcd(n, d) == 1:
4146
fractions_number += 1
4247
return fractions_number

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /