Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def BS (x, k):
- l = x
- r = 10 * x
- while r - l > 1:
- m = (r + l) // 2
- if m * k >= 10 * x:
- r = m
- else:
- l = m
- return l
- n = int (input())
- if n == 1:
- print (14)
- exit(0)
- ans = 0
- x = pow (10, n - 1)
- prev = x - 1
- for i in range (8, 0, -1):
- k = BS (x, i)
- print (k, prev)
- cnt = k - prev
- if i == 8:
- ans += cnt * 5
- elif i == 5:
- ans += cnt * 4
- elif i == 4:
- ans += cnt * 3
- elif i == 2:
- ans += cnt * 2
- elif i == 1:
- ans += cnt
- else:
- continue
- prev = k
- print (ans)
- print (ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement