思路:
设 为 的数位和。
因为 , 为 中的各个数位。又因为 ,所以 ,所以 。
因为 ,所以 ,又可以推到 。所以 。
所以我们可以从 枚举到 。第一个合法的答案就是最小值,如果没有合法的,输出 即可。
CODE:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(0);
#endif
cin.tie(0);
cout.tie(0);
ll y;
cin>>y;
for(ll i=sqrtl(y-1)+1;i<=sqrt(y-1)+1+10;i++){//注意是向上取整
if(i*i%9==y%9){
cout<<i<<"\n";
#ifndef ONLINE_JUDGE
system("pause");
#endif
return 0;
}
}
cout<<"-1\n";
#ifndef ONLINE_JUDGE
system("pause");
#endif
return 0;
}