-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathleyland_primes.py
44 lines (37 loc) · 932 Bytes
/
leyland_primes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# Author Dario Clavijo 2020
# GPLv3
# https://en.wikipedia.org/wiki/Leyland_number
# https://oeis.org/A094133
import gmpy2
def leyland_primes_naive(m):
tmp = []
for i in range(2, m):
for j in range(2, m):
x = i**j + j**i
if gmpy2.is_prime(x):
if x not in tmp:
tmp.append(x)
return tmp
def leyland_primes_oeis(N):
tmp = [3]
n = 2
n = 1
n1 = 1
while n < N:
n = 2 * n1**n1
k = n1 + 1
while k < N:
if gmpy2.gcd(n, k) == 1:
a = n**k + k**n
if a > N:
break
if gmpy2.is_prime(a):
if a not in tmp:
tmp.append(a)
print(a)
k += 1
n1 += 1
return tmp
if __name__ == "__main__":
print((leyland_primes_oeis(10**10)))