Advertisement
Korotkodul

F2_py1

Dec 10th, 2022
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import math
  2.  
  3. sh = False
  4. def f(A):
  5.     if sh:
  6.         print("A = ", A)
  7.     to2 = int(math.log(A, 2) + 10)
  8.     to3 = int(math.log(A, 3) + 10)
  9.     to5 = int(math.log(A, 5) + 10)
  10.     best = 10 ** 19
  11.     for i5 in range(to5):
  12.         for i3 in range(to3):
  13.            
  14.             ch = 5**i5 * 3**i3
  15.             if sh:
  16.                 print("i5 = ", i5)
  17.                 print("i3 = ", i3)
  18.             if ch >= A:
  19.                 best = min(best, ch)
  20.                 continue
  21.             i2 = int(math.log(A // (5 ** i5 * 3 ** i3), 2))
  22.             if (5 ** i5 * 3 ** i3 * 2 ** i2 < A):
  23.                 i2 += 1
  24.             now =  5 ** i5 * 3 ** i3 * 2 ** i2
  25.             best = min(best, now)
  26.     return best
  27.  
  28.  
  29. n = int(input())
  30. ar = []
  31. for i in range(n):
  32.     x = int(input())
  33.     ar.append(x)
  34.  
  35. for i in ar:
  36.     print(f(i))
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement