Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Ascending-primes/Python/ascending-primes-1.py
Normal file
8
Task/Ascending-primes/Python/ascending-primes-1.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from sympy import isprime
|
||||
|
||||
def ascending(x=0):
|
||||
for y in range(x*10 + (x%10) + 1, x*10 + 10):
|
||||
yield from ascending(y)
|
||||
yield(y)
|
||||
|
||||
print(sorted(x for x in ascending() if isprime(x)))
|
||||
18
Task/Ascending-primes/Python/ascending-primes-2.py
Normal file
18
Task/Ascending-primes/Python/ascending-primes-2.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def isprime(n):
|
||||
if n == 2: return True
|
||||
if n == 1 or n % 2 == 0: return False
|
||||
root1 = int(n**0.5) + 1;
|
||||
for k in range(3, root1, 2):
|
||||
if n % k == 0: return False
|
||||
return True
|
||||
|
||||
queue = [k for k in range(1, 10)]
|
||||
primes = []
|
||||
|
||||
while queue:
|
||||
n = queue.pop(0)
|
||||
if isprime(n):
|
||||
primes.append(n)
|
||||
queue.extend(n * 10 + k for k in range(n % 10 + 1, 10))
|
||||
|
||||
print(primes)
|
||||
Loading…
Add table
Add a link
Reference in a new issue