爆0求助

B3957 [GESP202403 三级] 完全平方数

RoYang19 @ 2024-07-18 11:38:31

#include<bits/stdc++.h>
using namespace std;
bool A_ll(int x){
    if(int(sqrt(x))*int(sqrt(x))==x){
        return true;
    }else{
        return false;
    }
}
int main(){
    int x=0,n;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            if(A_ll(a[j]+a[i])==true){
                x++;
            }
        }
    }
    cout<<x;
    return 0;
}

by King_and_Grey @ 2024-07-18 11:51:37

@Deon1214 额,看我的代码吧

#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans,n;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin >> n;
    int a[n + 1];
    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 (pow((int)sqrt(a[i] + a[j]),2) == a[i] + a[j])
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

by RoYang19 @ 2024-07-18 11:59:54

@greyandking ACcode吗?


by King_and_Grey @ 2024-07-18 12:06:00

@Deon1214 对


|