Submission

Status:

[PPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: devilpoohs

Problemset: anna

Language: cpp

Time: 0.256 second

Submitted On: 2026-03-05 13:25:25

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
    int ar[5];
    for(int i=0;i<5;i++){
        cin>>ar[i];
    }
    bool vis[4];
    set<pair<int,int>> ans;
    for(int i=0;i<5;i++){
        for(int j=1;j<=sqrt(ar[i]);j++){
            if(ar[i]%j==0){
                int c=j,d=ar[i]/j;
                // cout<<c<<' '<<d<<'|'<<d-c<<' '<<d/c<<' '<<d%c<<' '<<d+c;
                int cnt=0;
                memset(vis,false,sizeof(vis));
                for(int k=0;k<5;k++){
                    if(k==i) continue;
                    if(d-c==ar[k] and vis[0]==false){
                        vis[0]=true;
                        cnt++;
                    }else if(d/c==ar[k] and vis[1]==false){
                        vis[1]=true;
                        cnt++;
                    }else if(d%c==ar[k] and vis[2]==false){
                        vis[2]=true;
                        cnt++;
                    }else if(d+c==ar[k] and vis[3]==false){
                        vis[3]=true;
                        cnt++;
                    }
                }
                if(cnt==4 and c!=d){
                    ans.emplace(d,c);
                }
                // cout<<'\n';
            }
        }

    }
    
    
    if(ans.size()>1 or ans.empty()){
        cout<<"0 0\n";
    }else{
        cout<<ans.begin()->first<<' '<<ans.begin()->second<<'\n';
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    while(n--){
        solve();
    }
    return 0;
}