The_Law

Untitled

Apr 6th, 2018
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. def calc(k, d, i) :
  2.     res = ( (i - d + 1) * ((i - d + 1) + 1) )// 2
  3.     for j in range(d, 7):
  4.         if (j <= 5) :
  5.             res -= k
  6.     while (i % 7 != 0) :
  7.         if (i % 7 <= 5) :
  8.             res -= k
  9.         i -= 1
  10.     res -= (((i - 7) // 7) * 5) * k
  11.     return res
  12.  
  13. ans = 10 ** 18
  14. k, m, d = map(int, input().split())
  15.  
  16. for i in range(1, 10):
  17.     if (calc(k, d, i) < m):
  18.         ans = i - 1
  19.         break
  20.  
  21. ll = 1
  22. rr = 7 * 10 ** 10
  23. while (rr - ll > 1) :
  24.     mm = (ll + rr) // 2
  25.     if (m >= calc(k, d, 7 * mm)):
  26.         ll = mm
  27.     else :
  28.         rr = mm
  29. for i in range(max(d, 7 * (rr) - 100), max(d, 7 * rr + 100)):
  30.     if (m < calc(k, d, i)) :
  31.         ans = min(i - d, ans)
  32.         break
  33. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment