#include <bits/stdc++.h>
using namespace std;
int dp[10001][10001];
long long r(long long a,long long b){
if(dp[a][b]!=-1)return dp[a][b];
if(a<b)return dp[a][b]= r(b,a);
else if(a>=b&&b>1)return dp[a][b]=r(abs(a/b),b);
else if(a>=b&&b==1)return dp[a][b]=a;
}
int main(){
//ios_base::sync_with_stdio(false);cin.tie(NULL);
memset(dp,-1,sizeof dp);
int t;cin>>t;
z:while(t--){
long long a,b;
cin>>a>>b;
if(a==b||b==2||a==b*b){
cout<<a*b<<" "<<a<<"\n";goto z;
}
for(int i = 1;i<=10000;i++){
for(int j = 1;j<=10000;j++){
if(__gcd(i,j)==a&&r(i,j)==b){
cout<<i<<" "<<j<<"\n";
goto z;
}
}
}
}
return 0;
}
Compilation message
euklid.cpp: In function 'long long int r(long long int, long long int)':
euklid.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
9 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
391728 KB |
Output is correct |
2 |
Correct |
179 ms |
391676 KB |
Output is correct |
3 |
Correct |
182 ms |
391644 KB |
Output is correct |
4 |
Correct |
179 ms |
391672 KB |
Output is correct |
5 |
Correct |
176 ms |
391664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
391636 KB |
Output is correct |
2 |
Correct |
187 ms |
391620 KB |
Output is correct |
3 |
Correct |
185 ms |
391632 KB |
Output is correct |
4 |
Correct |
181 ms |
391624 KB |
Output is correct |
5 |
Correct |
178 ms |
391632 KB |
Output is correct |
6 |
Correct |
189 ms |
391644 KB |
Output is correct |
7 |
Correct |
184 ms |
391708 KB |
Output is correct |
8 |
Correct |
180 ms |
391740 KB |
Output is correct |
9 |
Correct |
182 ms |
391752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
391704 KB |
Output is correct |
2 |
Correct |
183 ms |
391660 KB |
Output is correct |
3 |
Correct |
181 ms |
391688 KB |
Output is correct |
4 |
Correct |
184 ms |
391728 KB |
Output is correct |
5 |
Correct |
179 ms |
391704 KB |
Output is correct |
6 |
Correct |
184 ms |
391716 KB |
Output is correct |
7 |
Correct |
184 ms |
391664 KB |
Output is correct |
8 |
Correct |
183 ms |
391628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
221 ms |
391628 KB |
Output is correct |
2 |
Correct |
273 ms |
391780 KB |
Output is correct |
3 |
Correct |
297 ms |
391668 KB |
Output is correct |
4 |
Correct |
284 ms |
391700 KB |
Output is correct |
5 |
Correct |
311 ms |
391620 KB |
Output is correct |
6 |
Correct |
322 ms |
391692 KB |
Output is correct |
7 |
Correct |
369 ms |
391712 KB |
Output is correct |
8 |
Correct |
391 ms |
391692 KB |
Output is correct |
9 |
Correct |
431 ms |
391748 KB |
Output is correct |
10 |
Correct |
477 ms |
391716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
221 ms |
391628 KB |
Output is correct |
2 |
Correct |
273 ms |
391780 KB |
Output is correct |
3 |
Correct |
297 ms |
391668 KB |
Output is correct |
4 |
Correct |
284 ms |
391700 KB |
Output is correct |
5 |
Correct |
311 ms |
391620 KB |
Output is correct |
6 |
Correct |
322 ms |
391692 KB |
Output is correct |
7 |
Correct |
369 ms |
391712 KB |
Output is correct |
8 |
Correct |
391 ms |
391692 KB |
Output is correct |
9 |
Correct |
431 ms |
391748 KB |
Output is correct |
10 |
Correct |
477 ms |
391716 KB |
Output is correct |
11 |
Execution timed out |
1109 ms |
391740 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
391728 KB |
Output is correct |
2 |
Correct |
179 ms |
391676 KB |
Output is correct |
3 |
Correct |
182 ms |
391644 KB |
Output is correct |
4 |
Correct |
179 ms |
391672 KB |
Output is correct |
5 |
Correct |
176 ms |
391664 KB |
Output is correct |
6 |
Correct |
179 ms |
391636 KB |
Output is correct |
7 |
Correct |
187 ms |
391620 KB |
Output is correct |
8 |
Correct |
185 ms |
391632 KB |
Output is correct |
9 |
Correct |
181 ms |
391624 KB |
Output is correct |
10 |
Correct |
178 ms |
391632 KB |
Output is correct |
11 |
Correct |
189 ms |
391644 KB |
Output is correct |
12 |
Correct |
184 ms |
391708 KB |
Output is correct |
13 |
Correct |
180 ms |
391740 KB |
Output is correct |
14 |
Correct |
182 ms |
391752 KB |
Output is correct |
15 |
Correct |
180 ms |
391704 KB |
Output is correct |
16 |
Correct |
183 ms |
391660 KB |
Output is correct |
17 |
Correct |
181 ms |
391688 KB |
Output is correct |
18 |
Correct |
184 ms |
391728 KB |
Output is correct |
19 |
Correct |
179 ms |
391704 KB |
Output is correct |
20 |
Correct |
184 ms |
391716 KB |
Output is correct |
21 |
Correct |
184 ms |
391664 KB |
Output is correct |
22 |
Correct |
183 ms |
391628 KB |
Output is correct |
23 |
Correct |
221 ms |
391628 KB |
Output is correct |
24 |
Correct |
273 ms |
391780 KB |
Output is correct |
25 |
Correct |
297 ms |
391668 KB |
Output is correct |
26 |
Correct |
284 ms |
391700 KB |
Output is correct |
27 |
Correct |
311 ms |
391620 KB |
Output is correct |
28 |
Correct |
322 ms |
391692 KB |
Output is correct |
29 |
Correct |
369 ms |
391712 KB |
Output is correct |
30 |
Correct |
391 ms |
391692 KB |
Output is correct |
31 |
Correct |
431 ms |
391748 KB |
Output is correct |
32 |
Correct |
477 ms |
391716 KB |
Output is correct |
33 |
Execution timed out |
1109 ms |
391740 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |