Submission #448197

#TimeUsernameProblemLanguageResultExecution timeMemory
448197ApiramEuklid (COCI20_euklid)C++14
4 / 110
1091 ms204 KiB
#include<bits/stdc++.h> using namespace std; int64_t solve(int a,int b){ if (a==1){ return b; } if (b==1)return a; if (a<b)solve(b/a,a); else return solve(a/b, b); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int test;cin>>test; while(test--){ int64_t g,h; cin>>g>>h; vector<pair<int,int>>ans; if (g==1){ cout<<1<<" "<<h<<endl; continue; } else if (g==h){ cout<<g<<" "<<h<<endl; continue; } else if (h==2){ while(true){ int left = 2,right =3; for (int i = left;i<=right;++i){ for (int j = left;j<i;++j){ if (__gcd(i,j)==g){ ans.push_back({i,j}); break; } } if (!ans.empty())break; } if (!ans.empty())break; left*=2; right*=2; } cout<<ans[0].first<<" "<<ans[0].second<<endl; continue; } for (int i = g;i<=200000;i+=g){ for (int j =g;j<=i;j+=g){ if (__gcd(i,j)==g){ if (solve(i,j)==h){ ans.push_back({i,j}); break; } } } if (!ans.empty())break; } cout<<ans[0].first<<" "<<ans[0].second<<endl; } return 0;}

Compilation message (stderr)

euklid.cpp: In function 'int64_t solve(int, int)':
euklid.cpp:8:15: warning: control reaches end of non-void function [-Wreturn-type]
    8 |  if (a<b)solve(b/a,a);
      |          ~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...