mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-20 21:49:48 +00:00
Improve Project Euler problem 058 solution 1 (#4782)
* Fix typo * Improve solution * Retest * Replace n with number
This commit is contained in:
parent
5f7bb3e9f7
commit
b55da04602
@ -33,11 +33,12 @@ So we check individually each one of these before incrementing our
|
|||||||
count of current primes.
|
count of current primes.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from math import isqrt
|
||||||
|
|
||||||
|
|
||||||
def isprime(d: int) -> int:
|
def isprime(number: int) -> int:
|
||||||
"""
|
"""
|
||||||
returns whether the given digit is prime or not
|
returns whether the given number is prime or not
|
||||||
>>> isprime(1)
|
>>> isprime(1)
|
||||||
0
|
0
|
||||||
>>> isprime(17)
|
>>> isprime(17)
|
||||||
@ -45,14 +46,15 @@ def isprime(d: int) -> int:
|
|||||||
>>> isprime(10000)
|
>>> isprime(10000)
|
||||||
0
|
0
|
||||||
"""
|
"""
|
||||||
if d == 1:
|
if number == 1:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
i = 2
|
if number % 2 == 0 and number > 2:
|
||||||
while i * i <= d:
|
return 0
|
||||||
if d % i == 0:
|
|
||||||
|
for i in range(3, isqrt(number) + 1, 2):
|
||||||
|
if number % i == 0:
|
||||||
return 0
|
return 0
|
||||||
i = i + 1
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user