#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6 + 10;
bool sieve[maxn];
vector<int> primes;
ll R(ll a, ll b) {
if (a<b) swap(a,b);
if (b==1) return a;
return R(a/b, b);
}
void solve1(ll g, ll h) {
assert(g==h);
cout<<g<<" "<<g*g<<"\n";
}
void solve2(ll g, ll h) {
assert(h==2);
cout<<2*g<<" "<<g<<"\n";
}
void solve3(ll g, ll h) {
assert(g==h*h);
ll a = g*h;
ll b = g;
assert(R(a,b)==h);
cout<<a<<" "<<b<<"\n";
}
void solve(ll g, ll h) {
for (ll x=1; ; x++) {
auto idx = lower_bound(primes.begin(),primes.end(), x*h) - primes.begin();
if (idx == (int)primes.size()) {
continue;
}
int p = primes[idx];
if (p/x == h) {
ll A = p*g; ll B = x*g;
if (R(A,B) == h) {
//cout<<g<<" "<<h<<": "<<A<<" "<<B<<endl;
assert(R(A,B)==h);
assert(__gcd(A,B)==g);
cout<<A<<" "<<B<<"\n";
return;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
for (int i=2; i<maxn; i++) {
if (!sieve[i]) {
primes.push_back(i);
for (int j=2*i; j<maxn; j+=i) {
sieve[j] = true;
}
}
}
int t;
cin>>t;
while (t--) {
ll g,h;
cin>>g>>h;
if (g==h) {
solve1(g,h);
} else if (h==2) {
solve2(g,h);
} else if (g==h*h) {
solve3(g,h);
} else {
solve(g,h);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1904 KB |
Output is correct |
2 |
Correct |
8 ms |
1904 KB |
Output is correct |
3 |
Correct |
7 ms |
1924 KB |
Output is correct |
4 |
Correct |
8 ms |
1904 KB |
Output is correct |
5 |
Correct |
7 ms |
1904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1904 KB |
Output is correct |
2 |
Correct |
8 ms |
1904 KB |
Output is correct |
3 |
Correct |
7 ms |
1904 KB |
Output is correct |
4 |
Correct |
8 ms |
1904 KB |
Output is correct |
5 |
Correct |
8 ms |
1904 KB |
Output is correct |
6 |
Correct |
8 ms |
1904 KB |
Output is correct |
7 |
Correct |
8 ms |
1904 KB |
Output is correct |
8 |
Correct |
7 ms |
1924 KB |
Output is correct |
9 |
Correct |
7 ms |
1904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1904 KB |
Output is correct |
2 |
Correct |
8 ms |
1924 KB |
Output is correct |
3 |
Correct |
7 ms |
1904 KB |
Output is correct |
4 |
Correct |
7 ms |
1904 KB |
Output is correct |
5 |
Correct |
8 ms |
1904 KB |
Output is correct |
6 |
Correct |
8 ms |
1904 KB |
Output is correct |
7 |
Correct |
8 ms |
2032 KB |
Output is correct |
8 |
Correct |
8 ms |
1904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1904 KB |
Output is correct |
2 |
Correct |
7 ms |
1904 KB |
Output is correct |
3 |
Correct |
7 ms |
1904 KB |
Output is correct |
4 |
Correct |
8 ms |
2032 KB |
Output is correct |
5 |
Correct |
8 ms |
1904 KB |
Output is correct |
6 |
Correct |
7 ms |
1904 KB |
Output is correct |
7 |
Correct |
7 ms |
1904 KB |
Output is correct |
8 |
Correct |
7 ms |
1904 KB |
Output is correct |
9 |
Correct |
7 ms |
1904 KB |
Output is correct |
10 |
Correct |
7 ms |
1904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1904 KB |
Output is correct |
2 |
Correct |
7 ms |
1904 KB |
Output is correct |
3 |
Correct |
7 ms |
1904 KB |
Output is correct |
4 |
Correct |
8 ms |
2032 KB |
Output is correct |
5 |
Correct |
8 ms |
1904 KB |
Output is correct |
6 |
Correct |
7 ms |
1904 KB |
Output is correct |
7 |
Correct |
7 ms |
1904 KB |
Output is correct |
8 |
Correct |
7 ms |
1904 KB |
Output is correct |
9 |
Correct |
7 ms |
1904 KB |
Output is correct |
10 |
Correct |
7 ms |
1904 KB |
Output is correct |
11 |
Execution timed out |
1093 ms |
1904 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1904 KB |
Output is correct |
2 |
Correct |
8 ms |
1904 KB |
Output is correct |
3 |
Correct |
7 ms |
1924 KB |
Output is correct |
4 |
Correct |
8 ms |
1904 KB |
Output is correct |
5 |
Correct |
7 ms |
1904 KB |
Output is correct |
6 |
Correct |
7 ms |
1904 KB |
Output is correct |
7 |
Correct |
8 ms |
1904 KB |
Output is correct |
8 |
Correct |
7 ms |
1904 KB |
Output is correct |
9 |
Correct |
8 ms |
1904 KB |
Output is correct |
10 |
Correct |
8 ms |
1904 KB |
Output is correct |
11 |
Correct |
8 ms |
1904 KB |
Output is correct |
12 |
Correct |
8 ms |
1904 KB |
Output is correct |
13 |
Correct |
7 ms |
1924 KB |
Output is correct |
14 |
Correct |
7 ms |
1904 KB |
Output is correct |
15 |
Correct |
8 ms |
1904 KB |
Output is correct |
16 |
Correct |
8 ms |
1924 KB |
Output is correct |
17 |
Correct |
7 ms |
1904 KB |
Output is correct |
18 |
Correct |
7 ms |
1904 KB |
Output is correct |
19 |
Correct |
8 ms |
1904 KB |
Output is correct |
20 |
Correct |
8 ms |
1904 KB |
Output is correct |
21 |
Correct |
8 ms |
2032 KB |
Output is correct |
22 |
Correct |
8 ms |
1904 KB |
Output is correct |
23 |
Correct |
8 ms |
1904 KB |
Output is correct |
24 |
Correct |
7 ms |
1904 KB |
Output is correct |
25 |
Correct |
7 ms |
1904 KB |
Output is correct |
26 |
Correct |
8 ms |
2032 KB |
Output is correct |
27 |
Correct |
8 ms |
1904 KB |
Output is correct |
28 |
Correct |
7 ms |
1904 KB |
Output is correct |
29 |
Correct |
7 ms |
1904 KB |
Output is correct |
30 |
Correct |
7 ms |
1904 KB |
Output is correct |
31 |
Correct |
7 ms |
1904 KB |
Output is correct |
32 |
Correct |
7 ms |
1904 KB |
Output is correct |
33 |
Execution timed out |
1093 ms |
1904 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |