跳到正文

题解

题解:UVA13140 Squares, Lists and Digital Sums

Charles_with_wkc约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
UVA13140

版本

  1. v1当前

思路:

枚举每个起点,如果符合要求就输出。

代码:

C++
for(int i=1;;i++){
		if(cheak(i*i)
		&&cheak((i+1)*(i+1))
		&&cheak((i+2)*(i+2))
		&&cheak((i+3)*(i+3))
		&&cheak((i+4)*(i+4))
		&&cheak((i+5)*(i+5))
		&&cheak((i+6)*(i+6))){
			cout<<i<<" "<<i*i<<endl;
			cout<<i+1<<" "<<(i+1)*(i+1)<<endl;
			cout<<i+2<<" "<<(i+2)*(i+2)<<endl;
			cout<<i+3<<" "<<(i+3)*(i+3)<<endl;
			cout<<i+4<<" "<<(i+4)*(i+4)<<endl;
			cout<<i+5<<" "<<(i+5)*(i+5)<<endl;
			cout<<i+6<<" "<<(i+6)*(i+6)<<endl;
			break;
		}
	}

暴力枚举。

C++
int cheak(int x){
	ans=0;
	while(x>0){
		ans+=x%10;
		x/=10;
	}
	int s=int(sqrt(ans));
	return ans==s*s;
}

判断函数。

原文