#include 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; }