Skip to content

Instantly share code, notes, and snippets.

@ArthurLoboLobo
Created March 18, 2024 19:13
Show Gist options
  • Save ArthurLoboLobo/07ef2cb044de0885f899d32377839e57 to your computer and use it in GitHub Desktop.
Save ArthurLoboLobo/07ef2cb044de0885f899d32377839e57 to your computer and use it in GitHub Desktop.
#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