Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. tc = int(input())
  2.  
  3. d9 = 10**9
  4. d18 = d9 * d9
  5.  
  6. for _ in range(tc):
  7.     n = int(input())  
  8.    
  9.     ans = -1
  10.     dif = 10**30
  11.    
  12.     i = 0
  13.     while (True):
  14.         t = n + i * d9
  15.         t *= t
  16.        
  17.         k = t // d18
  18.         p = k * d18
  19.        
  20.         if (k > d9):
  21.             break
  22.        
  23.         k += 1
  24.         p = k * d18
  25.         if (k > 0) and (k <= d9) and (dif > abs(t - p)):
  26.             dif = abs(t - p)
  27.             ans = k
  28.        
  29.         i += 1
  30.    
  31.     print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement