Created
June 14, 2017 21:34
-
-
Save vijayanandrp/c55228e5591ae598176eab8ed621e3cb to your computer and use it in GitHub Desktop.
Simple python code to solve Factorization Problems - Fermat Theorem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def gcd(a, b): | |
while a != b: | |
if a > b: | |
a = a - b | |
else: | |
b = b - a | |
return a | |
n = 80646413 | |
a = int(math.floor(math.sqrt(n))) | |
b = 0 | |
while(True): | |
b = a*a - n | |
t = b**(1/2) | |
if b == t*t: | |
b = t | |
break | |
a = a+1 | |
print 'the factor are ',gcd(a+b,n),gcd(a-b,n) | |
# u^2 - v^2 = n | |
# (u+v)(u-v) = n | |
# to find 'u' take floor(sqrt(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment