@[Accelerator_5](/user/152338) 应该是tmp有问题了,我输入20的时候tmp输出了11,14,17这些非完全平方数。
```cpp
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int pre[100005],ans;
int n;
int main(){
cin>>n;
int t=0;
for(int i=0;i*i<=n;i++){
pre[++t]=i*i;
}
for(int i=1;i<=t;i++){
for(int j=1;j<=t;j++){
if(pre[i]+pre[j]>n){
break;
}
for(int l=1;l<=t;l++){
if(pre[i]+pre[j]+pre[l]>n) {
break;
}
int tmp=n-pre[i]-pre[j]-pre[l];
if(sqrt(tmp)*sqrt(tmp)==tmp){
ans++;
printf("%d %d %d %d\n",pre[i],pre[j],pre[l],tmp);//这里加了一行
}
}
}
}
cout<<ans;
return 0;
}
```
by tangrunxi @ 2022-12-19 13:51:09
@[Accelerator_5](/user/152338) 您可以试一下下面这段代码。
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
int t=14;
cout<<sqrt(t)*sqrt(t);
return 0;
}
```
可以发现输出仍然是14,所以判断完全平方数不能通过这种方法判断。
by tangrunxi @ 2022-12-19 13:53:29
```floor(n)``` 是指 $n$ 向下取整,因此判断完全平方数可以写为:
```cpp
if(floor(sqrt(tmp))*floor(sqrt(tmp))==tmp){
ans++;
}
```
by tangrunxi @ 2022-12-19 13:55:01
@[tangrunxi](/user/231147) 谢谢!
by Accelerator_5 @ 2022-12-19 16:25:21
你别发代码啊
让的是你给他检查代码
by wstjy @ 2022-12-21 20:40:45