Skip to content

Commit 4024628

Browse files
committed
Add dixon.py
1 parent 5e31635 commit 4024628

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

dixon.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from gmpy2 import isqrt,gcd,next_prime
2+
import sys
3+
4+
def dixon(N,B=100):
5+
6+
tmp = []
7+
pairs = []
8+
9+
def primes(B):
10+
p = 2
11+
tmp = [p]
12+
while p < B-1:
13+
p = next_prime(p)
14+
tmp.append(p)
15+
return tmp
16+
17+
base = primes(B)
18+
19+
start = isqrt(N)
20+
i = start
21+
while i<=N:
22+
for j in range(len(base)):
23+
l = pow(i,2, N)
24+
r = pow(base[j],2,N)
25+
if l == r:
26+
pairs.append([i,base[j]])
27+
print(pairs)
28+
i+=1
29+
30+
for i in range(len(pairs)):
31+
x = pairs[i][0]
32+
y = pairs[i][1]
33+
tmp.append(gcd(x-y,N))
34+
35+
return tmp
36+
37+
print(dixon(int(sys.argv[1])))

0 commit comments

Comments
 (0)