Advertisement
prog3r

Untitled

Sep 16th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. # ------------------- fast io --------------------
  2. import os
  3. import sys
  4. from io import BytesIO, IOBase
  5. class FastIO(IOBase):
  6. newlines = 0
  7.  
  8. def __init__(self, file):
  9. self._fd = file.fileno()
  10. self.buffer = BytesIO()
  11. self.writable = "x" in file.mode or "r" not in file.mode
  12. self.write = self.buffer.write if self.writable else None
  13.  
  14. def read(self):
  15. while True:
  16. b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
  17. if not b:
  18. break
  19. ptr = self.buffer.tell()
  20. self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
  21. self.newlines = 0
  22. return self.buffer.read()
  23.  
  24. def readline(self):
  25. while self.newlines == 0:
  26. b = os.read(self._fd, max(os.fstat(self._fd).st_size, 8192))
  27. self.newlines = b.count(b"\n") + (not b)
  28. ptr = self.buffer.tell()
  29. self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
  30. self.newlines -= 1
  31. return self.buffer.readline()
  32.  
  33. def flush(self):
  34. if self.writable:
  35. os.write(self._fd, self.buffer.getvalue())
  36. self.buffer.truncate(0), self.buffer.seek(0)
  37. class IOWrapper(IOBase):
  38. def __init__(self, file):
  39. self.buffer = FastIO(file)
  40. self.flush = self.buffer.flush
  41. self.writable = self.buffer.writable
  42. self.write = lambda s: self.buffer.write(s.encode("ascii"))
  43. self.read = lambda: self.buffer.read().decode("ascii")
  44. self.readline = lambda: self.buffer.readline().decode("ascii")
  45. sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  46. input = lambda: sys.stdin.readline().rstrip("\r\n")
  47. # ------------------- fast io --------------------
  48. from math import ceil
  49. def prod(a, mod=10 ** 9 + 7):
  50. ans = 1
  51. for each in a:
  52. ans = (ans * each) % mod
  53. return ans
  54. def gcd(x, y):
  55. while y:
  56. x, y = y, x % y
  57. return x
  58. def lcm(a, b): return a * b // gcd(a, b)
  59. def binary(x, length=16):
  60. y = bin(x)[2:]
  61. return y if len(y) >= length else "0" * (length - len(y)) + y
  62. from bisect import bisect_left, bisect_right
  63. class Result:
  64. def __init__(self, index, value):
  65. self.index = index
  66. self.value = value
  67. class BinarySearch:
  68. def __init__(self):
  69. pass
  70.  
  71. @staticmethod
  72. def greater_than(num: int, func, size: int = 1):
  73. """Searches for smallest element greater than num!"""
  74. if isinstance(func, list):
  75. index = bisect_right(func, num)
  76. if index == len(func):
  77. return Result(None, None)
  78. else:
  79. return Result(index, func[index])
  80. else:
  81. alpha, omega = 0, size - 1
  82. if func(omega) <= num:
  83. return Result(None, None)
  84. while alpha < omega:
  85. if func(alpha) > num:
  86. return Result(alpha, func(alpha))
  87. if omega == alpha + 1:
  88. return Result(omega, func(omega))
  89. mid = (alpha + omega) // 2
  90. if func(mid) > num:
  91. omega = mid
  92. else:
  93. alpha = mid
  94.  
  95. @staticmethod
  96. def less_than(num: int, func, size: int = 1):
  97. """Searches for largest element less than num!"""
  98. if isinstance(func, list):
  99. index = bisect_left(func, num) - 1
  100. if index == -1:
  101. return Result(None, None)
  102. else:
  103. return Result(index, func[index])
  104. else:
  105. alpha, omega = 0, size - 1
  106. if func(alpha) >= num:
  107. return Result(None, None)
  108. while alpha < omega:
  109. if func(omega) < num:
  110. return Result(omega, func(omega))
  111. if omega == alpha + 1:
  112. return Result(alpha, func(alpha))
  113. mid = (alpha + omega) // 2
  114. if func(mid) < num:
  115. alpha = mid
  116. else:
  117. omega = mid
  118. bs = BinarySearch()
  119. ints = lambda: list(map(int, input().split()))
  120. for _ in range(int(input())):
  121. d = [2, 22]
  122. # for j in range(10000):
  123. # d.append(d[-1]//10*10*10+2)
  124. # su = 0
  125. # for j in range(len(d)):
  126. # su += d[j]
  127. # print(j+1, su%100000)
  128. n, = ints()
  129. if not n%2:
  130. if n >= 2228:
  131. print((n-2228)//2+4)
  132. elif n==2222:
  133. print(6)
  134. elif n==2224:
  135. print(10)
  136. elif n==2226:
  137. print(20)
  138. else:
  139. print(n//2+4390)
  140. else:
  141. if n > 2222:
  142. print((n-2223)*5+5)
  143. else:
  144. print(n*5+5+38885)
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement