-
-
Save ArthurLoboLobo/07ef2cb044de0885f899d32377839e57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main() { | |
long long D; | |
cin >> D; | |
long long resp = D; // resposta comeca sendo D | |
for(long long x = 0; x <= ceill(sqrtl(D)); x++) { | |
if(D - x*x <= 0) { | |
resp = min(resp,abs(D-x*x)); | |
} | |
else { | |
long long y1 = floorl(sqrtl(D-x*x)); | |
long long y2 = ceill(sqrtl(D-x*x)); | |
resp = min(resp,abs(D-x*x-y1*y1)); | |
resp = min(resp,abs(D-x*x-y2*y2)); | |
} | |
} | |
cout << resp << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment