Advertisement
Guest User

Untitled

a guest
Dec 8th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import re
  2. import math
  3.  
  4. 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)..)
  5. for i in primes:
  6. if (N%i)==0:
  7. return i
  8. def main():
  9. inp = open('primes.txt', 'r')
  10. rinp = ''.join(inp.readlines())
  11. 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.
  12. # then we have a list w/ all primes and lots of empty string occurences.
  13. # filter expression removes the empty strings. map changes the elements of the list of primes, which at that point are strings, to ints.
  14. cprimes = [((x**2)-1) for x in primes]
  15. revp = primes[::-1]
  16. for i in range(0,1000):
  17. f = factor(cprimes[i],revp)
  18. if (f>primes[i]):
  19. print("pair found, where a=%d,b=%d"%(primes[i],f))
  20. print "complete."
  21.  
  22. if __name__=='__main__':
  23. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement