mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Remove duplicate is_prime related functions (#5892)
* Fixes (#5434) * Update ciphers.rabin_miller.py maths.miller_rabin.py * Fixing ERROR maths/miller_rabin.py - ModuleNotFoundError and changing project_euler's isPrime to is_prime function names * Update sol1.py * fix: try to change to list * fix pre-commit * fix capital letters * Update miller_rabin.py * Update rabin_miller.py Co-authored-by: John Law <johnlaw.po@gmail.com>
This commit is contained in:

committed by
GitHub

parent
1d3d18bcd2
commit
1400cb86ff
@ -6,11 +6,11 @@ from .binary_exp_mod import bin_exp_mod
|
||||
# This is a probabilistic check to test primality, useful for big numbers!
|
||||
# if it's a prime, it will return true
|
||||
# if it's not a prime, the chance of it returning true is at most 1/4**prec
|
||||
def is_prime(n, prec=1000):
|
||||
def is_prime_big(n, prec=1000):
|
||||
"""
|
||||
>>> from .prime_check import prime_check
|
||||
>>> # all(is_prime(i) == prime_check(i) for i in range(1000)) # 3.45s
|
||||
>>> all(is_prime(i) == prime_check(i) for i in range(256))
|
||||
>>> from maths.prime_check import prime_check
|
||||
>>> # all(is_prime_big(i) == prime_check(i) for i in range(1000)) # 3.45s
|
||||
>>> all(is_prime_big(i) == prime_check(i) for i in range(256))
|
||||
True
|
||||
"""
|
||||
if n < 2:
|
||||
@ -48,4 +48,4 @@ def is_prime(n, prec=1000):
|
||||
if __name__ == "__main__":
|
||||
n = abs(int(input("Enter bound : ").strip()))
|
||||
print("Here's the list of primes:")
|
||||
print(", ".join(str(i) for i in range(n + 1) if is_prime(i)))
|
||||
print(", ".join(str(i) for i in range(n + 1) if is_prime_big(i)))
|
||||
|
Reference in New Issue
Block a user