站外题
  • 板块灌水区
  • 楼主lucy2012
  • 当前回复16
  • 已保存回复16
  • 发布时间2024/6/14 21:34
  • 上次更新2024/6/15 09:48:59
查看原帖
站外题
1252442
lucy2012楼主2024/6/14 21:34

求调:

#include<bits/stdc++.h>
using namespace std;
long long n,sn,tmp;
long long f(long long x){
	long long sum=0;
	while(x!=0){
		sum+=x%10;
		x/=10;
	}
	return x*x+sum*x;
}
int main(){   
    cin>>n;
    sn=sqrt(n);
	for(int i=sn-81;i<sn;i++){
		if(f(i)==n){
			tmp=1;
			cout<<i;
			break;
		}
	} 
	if(tmp==0)
	    cout<<-1;
    return 0;
}
2024/6/14 21:34
加载中...