Guest User

AMITNITI Solution

a guest
Jul 31st, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1.  
  2. import bisect
  3.  
  4. a = [2,7]
  5. size = 33
  6. for i in range(3,size):
  7. if i%2 == 0:
  8. a.append(a[-1]+7)
  9. else:
  10. a.append(a[-1]+3*a[-2])
  11. b = a[:16]
  12. c = a[16:]
  13.  
  14. allowedNumbersB = []
  15. allowedNumbersC = []
  16. def f(currentIndex, tillNowSum, type):
  17. if currentIndex >= size/2:
  18. if type == 0:
  19. allowedNumbersB.append(tillNowSum)
  20. else:
  21. allowedNumbersC.append(tillNowSum)
  22. else:
  23. if type == 0:
  24. f(currentIndex+1, tillNowSum+b[currentIndex], 0)
  25. f(currentIndex+1, tillNowSum, 0)
  26. else:
  27. f(currentIndex+1, tillNowSum+c[currentIndex], 1)
  28. f(currentIndex+1, tillNowSum, 1)
  29. f(0,0,0)
  30. f(0,0,1)
  31. allowedNumbersB = list(set(allowedNumbersB))
  32. allowedNumbersB.sort()
  33. allowedNumbersC = list(set(allowedNumbersC))
  34. allowedNumbersC.sort()
  35.  
  36. for _ in range(input()):
  37. n = input()
  38. ans = "NO"
  39. for i in allowedNumbersC:
  40. pos = bisect.bisect(allowedNumbersB, n-i)
  41. if pos != 0 and allowedNumbersB[pos-1] == n-i:
  42. ans = "YES"
  43. break
  44. print ans
Add Comment
Please, Sign In to add comment