lolamontes69

Python/ Cue Programming 2

May 19th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. from math import floor
  2.  
  3. def factors(n):
  4.     result = []
  5.     for i in range(2,n+1):              # test all integers between 2 and n
  6.         s = 0;
  7.         while n/i == floor(n/float(i)): # see if is n/i an integer.
  8.             n = n/float(i)
  9.             s += 1
  10.         if s > 0:
  11.             for k in range(s):
  12.                 result.append(i)        # i is a prime factor s times
  13.             if n == 1:
  14.                 return result
  15.  
  16. def isprime(n):
  17.     n = abs(int(n))
  18.     if n < 2:
  19.         return False
  20.     if n == 2:
  21.         return True
  22.     if not n & 1:
  23.         return False
  24.     for x in range(3, int(n**0.5)+1, 2):
  25.         if n % x == 0:
  26.             return False
  27.     return True
  28.  
  29. def calculate_first_primefibonnacci_after():
  30.     a = 1
  31.     b = 1
  32.     c = 0
  33.     # Assuming that the next prime fibonnacci will be less than this number
  34.     while c < 10000000000:
  35.         c = a + b
  36.         d = isprime(c)
  37.         if d:
  38.             if c > 227000:
  39.                 return c
  40.         a = b
  41.         b = c
  42.  
  43. def calculate_result(divisors):
  44.     total = 0
  45.     for a in divisors: total += a
  46.     return total
  47.  
  48.  
  49. if __name__ == "__main__":
  50.     number = (calculate_first_primefibonnacci_after()) + 1
  51.     divisors = factors(number)
  52.     result = calculate_result(divisors)
  53.     print "The Second Password is", result
Advertisement
Add Comment
Please, Sign In to add comment