fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cmath>
  4.  
  5. #define ll long long
  6. #define u unsigned
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11. u ll n;
  12. cin >> n;
  13. u ll mid = 0;
  14. u ll right = sqrt(n);
  15. u ll left = 0;
  16.  
  17.  
  18. while (left <= right) {
  19. mid = (left + right) / 2;
  20. if (mid >= sqrt(n)) {
  21. right = mid - 1;
  22. }
  23. else {
  24. left = mid + 1;
  25. }
  26. }
  27.  
  28. if (mid * mid == n) cout << mid << '\n';
  29. else cout << mid + 1 << '\n';
  30. }
Success #stdin #stdout 0.01s 5300KB
stdin
1000000002000000000
stdout
1000000002