Skip to content

Improve Project Euler problem 058 solution 1 #4782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions project_euler/problem_058/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@
count of current primes.

"""
from math import isqrt


def isprime(d: int) -> int:
def isprime(n: int) -> int:
"""
returns whether the given digit is prime or not
returns whether the given number is prime or not
>>> isprime(1)
0
>>> isprime(17)
1
>>> isprime(10000)
0
"""
if d == 1:
if n == 1:
return 0

i = 2
while i * i <= d:
if d % i == 0:
if n % 2 == 0 and n > 2:
return 0

for i in range(3, isqrt(n) + 1, 2):
if n % i == 0:
return 0
i = i + 1
return 1


Expand Down