結果
問題 | No.751 Frac #2 |
ユーザー |
|
提出日時 | 2024-12-15 18:37:36 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,173 bytes |
コンパイル時間 | 3,074 ms |
コンパイル使用メモリ | 247,224 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 18:37:41 |
合計ジャッジ時間 | 4,228 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#ifndef LOCAL #include <bits/stdc++.h> using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif using S = pair<int64_t, int64_t>; S div(S a, S b) { S res{a.first * b.second, a.second * b.first}; int64_t g = std::gcd(res.first, res.second); res.first /= g; res.second /= g; return res; } void solve() { int N; cin >> N; S nu; cin >> nu.first; nu.second = 1; for (int i = 1; i < N; i++) { S cur; cin >> cur.first; cur.second = 1; nu = div(nu, cur); } int M; cin >> M; vector<int> B(M - 1); for (int i = 0; i < M - 1; i++) cin >> B[i]; S de; cin >> de.first; de.second = 1; for (int i = M - 1; i--;) { S cur; cur.first = B[i]; cur.second = 1; de = div(cur, de); } S ans = div(nu, de); if(ans.second < 0) { ans.first *= -1; ans.second = -ans.second; } cout << ans.first << " " << ans.second << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }