Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #http://math.stackexchange.com/questions/517429/
- from fractions import Fraction
- def gen():
- num = 0
- den = 0
- k = 1
- while True:
- num += k**k
- den += k
- yield Fraction(num, den)
- k += 1
- if __name__ == "__main__":
- n = 1
- for number in gen():
- if number.denominator == 1:
- print("n = %i works!" % n)
- if n > 1:
- break
- if n % 100 == 0:
- print("n = %i does not work :-(" % n)
- n += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement