fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. LL n;
  5. LL test(LL k){
  6. // return number of turns it takes
  7. LL total = n;
  8. LL eaten = 0;
  9. LL rounds = 0;
  10. while(total > 0){
  11. LL a = min(total, k);
  12. total -= a;
  13. eaten += a;
  14. rounds++;
  15. total -= (total / 10);
  16. }
  17. if(eaten >= n-eaten){
  18. return 1;
  19. }
  20. return 0;
  21. }
  22. int main(){
  23. cin >> n;
  24. LL s = 0;
  25. LL e = 1000000000000000000LL; // yes
  26. while(s + 1 < e){
  27. LL m = (s+e)/2;
  28. if(test(m)){
  29. e = m;
  30. } else {
  31. s = m;
  32. }
  33. }
  34. cout << e << endl;
  35. }
Success #stdin #stdout 0s 4520KB
stdin
1000000000000000000
stdout
39259424579862572