이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
//#define M ll(1e9 + 7)
#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
#define eps (ld)1e-9
using namespace std;
typedef long long ll;
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef double ld;
typedef unsigned long long ull;
typedef short int si;
const int N = 2e5 + 500;
ll r(ll x, ll y) {
if (x > y) {
swap(x, y);
}
if (x == 1)
return y;
// cerr << x << " " << y << el;
return r(x, y / x);
}
bool gd(ll a, ll b) {return (b % a == 0);}
void solve() {
int g, h;
cin >> g >> h;
if (g == h) {
cout << g << " " << g << el;
return;
}
if (g < h) {
ll hop = g * 1ll * h;
ll st = hop;
ll a = g * 1ll * h;
ll b = hop * 2ll + g;
int cnt = 0;
int c = 0;
while (1) {
int R = r(a, b);
if (R == h) {
break;
}
if (R == st) {
cnt++;
hop *= st;
}
b += hop;
}
//
cout << a << " " << b << el;
cout << r(a, b) << el;
return;
}
ll a = g;
ll b = g * 1ll * 2;
int cnt = 0;
ll hop = g;
int c = 0;
while (1) {
int R = r(a, b);
if (R == h) {
break;
}
if (R == g) {
cnt++;
hop *= g;
}
b += hop;
}
//
cout << a << " " << b << el;
// cout << r(a, b) << el;
}
int main()
{
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());;
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// in("toys.in");
// out("toys.out");
// in("input.txt");
// out("output.txt");
// cerr.precision(9); cerr << fixed;
// clock_t tStart = clock();
// for (int i = 4; i <= 50; i++) {
// cout << __gcd(4, i) << " " << r(4, i) << el;
// }
int q;
cin >> q;
while (q--) {
solve();
}
}
/*
7
4 6 7 2 3 1 5
*/
컴파일 시 표준 에러 (stderr) 메시지
euklid.cpp: In function 'void solve()':
euklid.cpp:65:13: warning: unused variable 'c' [-Wunused-variable]
65 | int c = 0;
| ^
euklid.cpp:90:9: warning: unused variable 'c' [-Wunused-variable]
90 | int c = 0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |