Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long n, m, zile, cp;
  8. cin >> n >> m;
  9. long long sgaus2 = 0;
  10. cp = n;
  11. zile = m + 1;
  12. if(zile >= n) cout << n;
  13. else
  14. {
  15. long long pas = 1ll << 30, i = 0;
  16. while(pas)
  17. {
  18. long long sgaus;
  19. if((i + pas - m) % 2)
  20. {
  21. sgaus = (i + pas + 1 - m) / 2;
  22. sgaus *= (i + pas - m);
  23. }
  24. else
  25. {
  26. sgaus = (i + pas - m) / 2;
  27. sgaus *= (i + pas + 1 - m);
  28. }
  29. sgaus += m;
  30. if(n - sgaus>= 0)
  31. {
  32. //cout << n << endl;
  33. n -= sgaus;
  34. // cout << n << ' ' << sgaus << endl;
  35. // n += m * (i + pas - m - 1);
  36. i+= pas;
  37. cout << sgaus << ' ' << i << endl;
  38. }
  39. pas /= 2;
  40. }
  41. if(n > 0)
  42. i++;
  43. zile = i;
  44. cout << zile << endl;
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement