-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathz3_solver.py
More file actions
21 lines (19 loc) · 729 Bytes
/
z3_solver.py
File metadata and controls
21 lines (19 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from z3 import Solver, Int ,set_param
from gmpy2 import isqrt
set_param('parallel.enable', True)
def z3_solve(self, n, timeout_amount):
s = Solver()
s.set("timeout", timeout_amount * 1000)
p = Int("x")
q = Int("y")
i = int(isqrt(n))
if i**2 == n: # check if we are dealing with a perfect square otherwise try to SMT.
return i,i
s.add(p * q == n, p > 1, q > i, q > p) # In every composite n=pq,there exists a p>sqrt(n) and q<sqrt(n).
try:
s_check_output = s.check()
res = s.model()
return res[p].as_long(), res[q].as_long()
except:
return None, None
print(z3_solve(int(sys.argv[1])))