Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- long long n, a, b;
- cin >> n >> a >> b;
- long long S = a;
- long long E = b;
- while(S <= E) {
- long long middle = (S + E) / 2;
- long long x = (middle * middle) + (200 * middle);
- long long tmp = middle;
- long long zbir = 0;
- while(tmp > 0) {
- zbir += (tmp % 10);
- tmp /= 10;
- }
- x += zbir;
- if(x == n) {
- cout << middle << endl;
- return 0;
- }
- if(x > n) {
- E = middle - 1;
- }
- else {
- S = middle + 1;
- }
- }
- cout << -1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement