qsbb @ 2024-08-27 19:47:14
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000010];
int main(){
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
int num = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j--){
int k = sqrt(a[i] + a[j]);
if(a[i] + a[j] == k * k){
num ++;
}
}
}
cout << num;
}
by Dress @ 2024-08-27 20:00:08
@just01 已AC求关QWQ
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000010];
int main(){
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
int num = 0;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){//j = 0 -> j = i + 1 j-- -> j++
int k = sqrt((int) a[i] + a[j]);//sqrt(a[i] + a[j]) -> sqrt((int) a[i] + a[j])
if(sqrt(a[i] + a[j]) == k){//a[i] + a[j] == k * k -> sqrt(a[i] + a[j]) == k
num ++;
}
}
}
cout << num;
}
AC记录
by qsbb @ 2024-08-28 18:05:47
谢谢
by qsbb @ 2024-08-28 18:06:11
@Dress 谢谢
by cuixizhou @ 2024-09-06 20:52:37
@just01 求关+1
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a[1005],g=0;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(int(sqrt(a[i]+a[j]))==sqrt(a[i]+a[j]*1.0)) g++;
cout<<g;
return 0;
}