fork download
  1. def hamming(n):
  2. arr = [1]
  3. while len(arr) <= n:
  4. for i in range(2,5000):
  5. a = i
  6. while a >= 1:
  7. if a == 1:
  8. if len(arr) <= 5000:
  9. arr.append(i)
  10. i += 1
  11. else:
  12. break
  13. elif a % 2 == 0:
  14. a = a / 2
  15. #return a
  16. elif a % 2 == 0:
  17. a = a / 3
  18. #return a
  19. elif a % 2 == 0:
  20. a = a / 5
  21. #return a
  22. else:
  23. i += 1
  24. print(arr)
  25.  
  26.  
  27. hamming(10)# your code goes here
Time limit exceeded #stdin #stdout 5s 9288KB
stdin
Standard input is empty
stdout
Standard output is empty