fork download
  1. def fibonacci_gen(n):
  2. a, b = 0, 1
  3. while b < n:
  4. a, b = b, a+b
  5. yield b
  6.  
  7. def zeckendorf(n):
  8. Fib = list(fibonacci_gen(n))
  9. while n > 0:
  10. if Fib[-1] <= n:
  11. n -= Fib[-1]
  12. yield Fib.pop()
  13. if Fib:
  14. Fib.pop()
  15.  
  16. def handle_input(nums):
  17. for num in nums.splitlines()[1:int(nums.splitlines()[0])+1]:
  18. print(num, '=', ' + '.join(map(str,zeckendorf(int(num)))))
  19.  
  20. handle_input('5\n20\n13\n9432944792\n12\n2345239\nstop here\ntoo late\nstoooaapp')
  21.  
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
20 = 13 + 5 + 2
13 = 13
9432944792 = 7778742049 + 1134903170 + 433494437 + 63245986 + 14930352 + 5702887 + 1346269 + 514229 + 46368 + 17711 + 987 + 233 + 89 + 21 + 3 + 1
12 = 8 + 3 + 1
2345239 = 2178309 + 121393 + 28657 + 10946 + 4181 + 1597 + 144 + 8 + 3 + 1