結果
問題 | No.751 Frac #2 |
ユーザー |
|
提出日時 | 2020-04-21 21:23:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 984 bytes |
コンパイル時間 | 772 ms |
コンパイル使用メモリ | 67,920 KB |
最終ジャッジ日時 | 2025-01-09 22:10:12 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <iostream> #include <numeric> using lint = long long; void solve() { lint x = 1, y = 1; auto reduce = [&]() { if (y < 0) { x = -x; y = -y; } auto g = std::gcd(x, y); x /= g, y /= g; }; { int n; std::cin >> n; for (int i = 0; i < n; ++i) { lint a; std::cin >> a; if (i == 0) { x *= a; } else { y *= a; } reduce(); } } { int n; std::cin >> n; for (int i = 0; i < n; ++i) { lint b; std::cin >> b; if (i % 2 == 0) { y *= b; } else { x *= b; } reduce(); } } std::cout << x << " " << y << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }