xuzhengfei666 @ 2025-01-10 19:28:44
#include<bits/stdc++.h>
using namespace std;
int n,cnt,a[1005];
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++)
{
if(sqrt(a[i]+a[j])*sqrt(a[i]+a[j])==(a[i]+a[j]))
cnt++;
}
}
cout<<cnt;
return 0;
}
by chengjindong @ 2025-01-10 19:57:45
by chengjindong @ 2025-01-10 19:58:50
sqrt
前方个强制转换,换成整数
#include<bits/stdc++.h>
using namespace std;
int n,cnt,a[1005];
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;j<=n;j++)
{
if((int)sqrt(a[i]+a[j])*(int)sqrt(a[i]+a[j])==(a[i]+a[j]))
cnt++;
}
}
cout<<cnt;
return 0;
}
@xuzhengfei666
by chengjindong @ 2025-01-10 19:59:48
等会儿,我眼瞎了,就是 i+1
#include<bits/stdc++.h>
using namespace std;
int n,cnt,a[1005];
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++)
{
if((int)sqrt(a[i]+a[j])*(int)sqrt(a[i]+a[j])==(a[i]+a[j]))
cnt++;
}
}
cout<<cnt;
return 0;
}
by xuzhengfei666 @ 2025-01-10 20:19:42
@chengjindong 谢谢