Submission #374462

#TimeUsernameProblemLanguageResultExecution timeMemory
374462VimmerEuklid (COCI20_euklid)C++14
20 / 110
1 ms492 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") #define N 1005 #define NN 1005000 #define PB push_back #define M ll(1e9 + 7) #define all(x) x.begin(), x.end() #define sz(x) int(x.size()) #define pri(x) cout << x << endl #define endl '\n' #define _ << " " << #define F first #define S second using namespace std; //using namespace __gnu_pbds; //typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef short int si; ll brd(ll a, ll b) { if (b > a) swap(a, b); if (b == 1) return a; return brd(a / b, b); } pair <ll, ll> fnd(ll gc, ll x) { ll p = (x + x) / gc; ll r = p * gc; if (r == x + x) r -= gc; p = x / gc; ll l = p * gc; if (l != x) l += gc; for (ll y = l; y <= r; y += gc) { if (__gcd(y, x) == gc) return {y, x}; for (ll t = x * y; t < (x + 1) * y; t++) if (__gcd(y, t) == gc) return {y, t}; } for (ll y = x; y < x + x; y++) { if (y % gc == 0) continue; r = (y * (x + 1)); r /= gc; r *= gc; if (r == (y * (x + 1))) r -= gc; l = (y * x) / gc; l *= gc; if (l != y * x) l += gc; for (ll nx = l; nx <= r; nx += gc) { for (ll t = nx * y; t < nx * (y + 1); t++) if (__gcd(t, nx) == gc) return {nx, t}; } } return {0, 0}; } int main() { ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("1.in", "r", stdin); int q; cin >> q; for (; q > 0; q--) { ll gc, bd; cin >> gc >> bd; if (gc == bd) { pri(gc _ bd); continue; } if (bd == 2) { pri(gc + gc _ gc); continue; } if (gc == bd && bd == 1) { pri(3 _ 2); continue; } if (bd * bd == gc) { pri(gc _ bd * gc); continue; } pair <ll, ll> pt = fnd(gc, bd); pri(pt.F _ pt.S); } }
#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...