Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import math
- def factor(N,primes): #returns largest prime factor of a number. we can just use primes bc/ all cprimes are 1 less than the sqrt of their primes, so the largest prime factor will always be in primes. (we compute prime factors up to sqrt(n)..)
- for i in primes:
- if (N%i)==0:
- return i
- def main():
- inp = open('primes.txt', 'r')
- rinp = ''.join(inp.readlines())
- primes = map(lambda b: int(b), filter(lambda a: a!= '', [s for s in re.split('[\s\t\n]',rinp)])) #regex takes the huge string and splits it on whitespace/tabs/newlines.
- # then we have a list w/ all primes and lots of empty string occurences.
- # filter expression removes the empty strings. map changes the elements of the list of primes, which at that point are strings, to ints.
- cprimes = [((x**2)-1) for x in primes]
- revp = primes[::-1]
- for i in range(0,1000):
- f = factor(cprimes[i],revp)
- if (f>primes[i]):
- print("pair found, where a=%d,b=%d"%(primes[i],f))
- print "complete."
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement