Advertisement
themoosemind

Is fraction integer for any n?

Apr 15th, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. #http://math.stackexchange.com/questions/517429/
  4.  
  5. from fractions import Fraction
  6.  
  7.  
  8. def gen():
  9.     num = 0
  10.     den = 0
  11.     k = 1
  12.     while True:
  13.         num += k**k
  14.         den += k
  15.         yield Fraction(num, den)
  16.         k += 1
  17.  
  18. if __name__ == "__main__":
  19.     n = 1
  20.     for number in gen():
  21.         if number.denominator == 1:
  22.             print("n = %i works!" % n)
  23.             if n > 1:
  24.                 break
  25.         if n % 100 == 0:
  26.             print("n = %i does not work :-(" % n)
  27.         n += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement