Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <string>
- #include <vector>
- #include <queue>
- #include <iostream>
- #include <cmath>
- #include <sstream>
- #include <map>
- #include <set>
- #include <numeric>
- #include <memory.h>
- #include <cstdio>
- #include <assert.h>
- using namespace std;
- #define pb push_back
- #define INF 1011111111
- #define FOR(i, a, b) for (int _n(b), i(a); i < _n; i++)
- #define rep(i, n) FOR(i, 0, n)
- #define CL(a, v) memset((a), (v), sizeof(a))
- #define mp make_pair
- #define X first
- #define Y second
- #define all(c) (c).begin(), (c).end()
- #define SORT(c) sort(all(c))
- typedef long long ll;
- typedef vector<int> VI;
- typedef pair<int, int> pii;
- /*** TEMPLATE CODE ENDS HERE */
- ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); }
- void solve() {
- ll R, S;
- cin >> R >> S;
- // R >= S
- ll T = 0;
- if (R >= S) {
- T = ll(R / S) * S;
- R %= S;
- }
- if (4 * R > S) {
- cout << T + S << " " << 0 << "/" << 1 << endl;
- return;
- }
- T += R;
- R = R * R;
- ll g = gcd(R, S);
- R /= g;
- S /= g;
- if (R == 0) S = 1;
- if (R) S *= 2;
- cout << T << " " << R << "/" << S << endl;
- }
- int main() {
- #ifdef LOCAL_HOST
- freopen("input.txt", "r", stdin);
- // freopen("output.txt","w",stdout);
- #endif
- ios_base::sync_with_stdio(false);
- int T;
- cin >> T;
- while (T--) {
- solve();
- }
- #ifdef LOCAL_HOST
- printf("TIME: %.3lf\n", double(clock()) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement