Created
July 19, 2015 11:34
-
-
Save hugopeixoto/00a4c74c15b746784e8d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
def roots(n): | |
for a in range(0, n): | |
if (a*a) % n == 1: | |
yield a | |
def prime(n): | |
for a in range(2, n): | |
if n % a == 0: | |
return False | |
return True | |
def composite(n): return not prime(n) | |
def factors(n): | |
a = 3 | |
while n != 1: | |
if n % a == 0: | |
yield a | |
n /= a | |
else: | |
a += 2 | |
print("{0:<7} {1:<14} {2:<40} {3}".format("N", "Factors", "Roots", "Conjecture")) | |
for n in range(3, 20, 2): | |
if composite(n): | |
f = list(set(factors(n))) | |
r = list(roots(n)) | |
c = 2**len(f) == len(r) | |
print("{0:<7} {1:<14} {2:<40} {3}".format(n, f, r, c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment