結果
問題 | No.751 Frac #2 |
ユーザー |
![]() |
提出日時 | 2018-11-16 15:14:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 939 bytes |
コンパイル時間 | 755 ms |
コンパイル使用メモリ | 75,468 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 14:10:11 |
合計ジャッジ時間 | 1,647 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; ll gcd(ll n, ll m) { if (n < m) swap(n, m); while (m != 0) { ll r = n % m; n = m; m = r; } return n; } int main() { ll p[2] = { 1, 1 }; int n; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; p[i != 0] *= a; } int m; cin >> m; for (int i = 0; i < m; i++) { int b; cin >> b; p[i % 2 == 0] *= b; } if (p[0] == 0) { cout << "0 1" << endl; } else { if (p[1] < 0) p[0] *= -1, p[1] *= -1; if (p[0] < 0) { cout << '-'; p[0] *= -1; } ll t = gcd(p[0], p[1]); p[0] /= t; p[1] /= t; cout << p[0] << ' ' << p[1] << endl; } return 0; }