File tree Expand file tree Collapse file tree 1 file changed +14
-21
lines changed Expand file tree Collapse file tree 1 file changed +14
-21
lines changed Original file line number Diff line number Diff line change 3
3
4
4
def dixon (N ,B = 7 ):
5
5
6
- tmp = []
7
- pairs = []
8
-
9
6
def primes (B ):
10
7
p = 2
11
8
tmp = [p ]
@@ -15,28 +12,24 @@ def primes(B):
15
12
return tmp
16
13
17
14
base = primes (B )
18
-
19
- #print(base)
20
-
21
15
start = isqrt (N )
22
16
i = start
17
+
18
+ ii2N = []
23
19
while i <= N :
24
- for j in range (len (base )):
25
- l = pow (i ,2 , N )
26
- r = pow (base [j ],2 ,N )
27
- #print(i,j,l,r)
28
- if l == r :
29
- pairs .append ([i ,base [j ]])
30
- #print(pairs)
20
+ ii2N .append ((i ,pow (i ,2 ,N )))
31
21
i += 1
32
22
33
- #print(pairs)
34
-
35
- for i in range (len (pairs )):
36
- x = pairs [i ][0 ]
37
- y = pairs [i ][1 ]
38
- f = (gcd (x - y ,N ))
39
- if 1 < f < N :
40
- return f ,N // f
23
+ basej2N = []
24
+ for j in range (0 ,len (base )):
25
+ basej2N .append (pow (base [j ],2 ,N ))
26
+
27
+ for i ,i2N in ii2N :
28
+ for k in range (0 ,len (base )):
29
+ if i2N == basej2N [k ]:
30
+ f = gcd (i - base [k ],N )
31
+ if 1 < f < N :
32
+ return f ,N // f
33
+ return - 1
41
34
42
35
print (dixon (int (sys .argv [1 ])))
You can’t perform that action at this time.
0 commit comments