結果
問題 |
No.1931 Fraction 2
|
ユーザー |
|
提出日時 | 2025-05-22 23:14:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 954 bytes |
コンパイル時間 | 1,762 ms |
コンパイル使用メモリ | 197,468 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-22 23:14:15 |
合計ジャッジ時間 | 7,014 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 WA * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 998244353; // GCD function int gcd(int a, int b) { while (b) tie(a, b) = make_pair(b, a % b); return a; } // Modular function to keep result in [0, MOD) int mod(int x) { x %= MOD; if (x < 0) x += MOD; return x; } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int num = 0, den = 1; // Start with 0/1 for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; // num/den + x/y = (num * y + x * den) / (den * y) int new_num = num * y + x * den; int new_den = den * y; int g = gcd(abs(new_num), new_den); num = new_num / g; den = new_den / g; } // Reduce once more just to be sure int g = gcd(abs(num), den); num /= g; den /= g; cout << mod(num) << ' '; cout << mod(den) << '\n'; return 0; }