#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+5;
int n,m;
int a[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
int x=i*i;
int y=(i+1)*(i+1);
if(n==x||n==y){
cout<<0;
return;
}
if(n>=x&&n<=y){
if(i&1){
if(n&1){
cout<<(n-i*i)/2;
return;
}
else{
cout<<(pow(i+1,2)-n)/2;
return;
}
}
else{
if(n&1){
cout<<(pow(i+1,2)-n)/2;
return;
}
else{
cout<<(n-i*i)/2;
return;
}
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt=1;
// cin>>tt;
while(tt--) solve();
return 0;
}
小红的完全平方数(数学)--牛客周赛 Round 43-B
于 2024-05-20 17:24:15 首次发布