Advertisement
Josif_tepe

Untitled

May 26th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.     long long n, a, b;
  7.     cin >> n >> a >> b;
  8.     long long S = a;
  9.     long long E = b;
  10.     while(S <= E) {
  11.         long long middle = (S + E) / 2;
  12.         long long x = (middle * middle) + (200 * middle);
  13.         long long tmp = middle;
  14.         long long zbir = 0;
  15.         while(tmp > 0) {
  16.             zbir += (tmp % 10);
  17.             tmp /= 10;
  18.         }
  19.         x += zbir;
  20.        
  21.         if(x == n) {
  22.             cout << middle << endl;
  23.             return 0;
  24.         }
  25.         if(x > n) {
  26.             E = middle - 1;
  27.         }
  28.         else {
  29.             S = middle + 1;
  30.         }
  31.     }
  32.  
  33.     cout << -1 << endl;
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement