yuhongyue @ 2024-08-14 14:40:53
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e4+50;
int n,cnt=0;
int a[N];
signed main(){
std::cin>>n;
for(int i=1;i<=n;i++){
std::cin>>a[i];
}
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
int q=a[i]+a[j];
int w=sqrt(q);
if(sqrt(a[i]+a[j])==w){
cnt++;
}
}
}
std::cout<<cnt;
return 0;
}
by _____QWQ_____ @ 2024-08-14 14:50:46
判断有问题
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+50;
int n,cnt=0;
int a[N];
signed main(){
std::cin>>n;
for(int i=1;i<=n;i++){
std::cin>>a[i];
}
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
int q=a[i]+a[j];
float w=sqrt(q); ////BUG
if((int)sqrt(a[i]+a[j])==w){
cnt++;
}
}
}
std::cout<<cnt;
return 0;
}
@yuhongyue
by yuhongyue @ 2024-08-14 14:52:25
@QWQ 谢谢,过了,
by SmileString @ 2024-08-14 14:55:43
@QWQ 不是判断有问题,而是循环有问题,只改循环也对
by _____QWQ_____ @ 2024-08-14 14:59:24
@Dream66666 啊确实(循环只是随手改的)