Submission #872238

# Submission time Handle Problem Language Result Execution time Memory
872238 2023-11-12T15:01:41 Z NotLinux Euklid (COCI20_euklid) C++17
20 / 110
29 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 7;
int g,h;
inline int gcd(int a, int b){
	if(a > b)return gcd(b,a);
	else if(a == 0)return b;
	else return gcd(b%a,a);
}
inline int R(int a, int b){
	if(a < b)return R(b,a);
	else if(a >= b and b > 1)return R(a/b,b);
	else return a;
}
inline int closest(int ql , int qr , int qj){
	//cout << "bs : " << ql << " " << qr << " " << qj << endl;
	int l = ql , r = qr;
	while(l < r){
		int mid = (l+r)/2;
		if(R(mid*g , qj/mid) >= h)r = mid;
		else l = mid+1;
	}
	//cout << "done" << endl;
	return l;
}
void solve(){
	cin >> g >> h;
	for(int j = 1;j<=N;j++){
		int l = j/2+1 , r = j , cur = 1;
		while(true){
			int temp = closest(l,r,j);
			//cout << "temp : " << temp << endl;
			if(R(temp*g , j/temp) == h){
				cout << temp*g << " " << j*g << endl;
				return;
			}
			r = l-1;
			if(r == 0)break;
			cur = j/r;
			l = j/(cur+1) + 1;
		}
	}
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;cin >> testcase;
	while(testcase--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 29 ms 348 KB Output is correct
3 Correct 23 ms 348 KB Output is correct
4 Correct 17 ms 348 KB Output is correct
5 Correct 12 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 29 ms 348 KB Output is correct
17 Correct 23 ms 348 KB Output is correct
18 Correct 17 ms 348 KB Output is correct
19 Correct 12 ms 348 KB Output is correct
20 Correct 8 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Halted 0 ms 0 KB -