huangluochengshuo @ 2024-04-26 21:15:38
#include<bits/stdc++.h>
using namespace std;
int a[100003],ans,s,m,n;
int main()
{
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++)
{
s=a[i]+a[j];
for(int z=1;z<=s;z++)
{
if(s%z==0)
{
m=s/z;
}
if(m==z)
{
ans++;
break;
}
}
}
cout<<ans;
return 0;
}
by King_Songgy @ 2024-06-10 21:35:35
重写一下
by 0x3E @ 2024-06-20 21:09:23
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N];
int main(){
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int m = a[i] + a[j];
int t = sqrt(m + 1e-7);
if(t * t == m)
ans++;
}
}
cout<<ans<<"\n";
}