Все задачи на 5.10.17 13:00
This commit is contained in:
26
uts/session_py/dist_march_2k17/Peter.py
Normal file
26
uts/session_py/dist_march_2k17/Peter.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
sys.stdin = open("input.txt", "r")
|
||||
sys.stdout = open("output.txt", "w")
|
||||
s = int(input())
|
||||
l = 1
|
||||
h = int(10e18)
|
||||
while l <= h:
|
||||
mid = (l+h)//2
|
||||
x = mid
|
||||
now = mid
|
||||
while x != 0:
|
||||
st = str(x)
|
||||
st = st[:-1]
|
||||
if len(st) == 0:
|
||||
break
|
||||
x = int(st)
|
||||
now += x
|
||||
if now == s :
|
||||
print(mid)
|
||||
quit()
|
||||
elif now < s :
|
||||
l = mid + 1
|
||||
else :
|
||||
h = mid - 1
|
||||
print(-1)
|
||||
Reference in New Issue
Block a user