結果
問題 | No.751 Frac #2 |
ユーザー |
|
提出日時 | 2019-09-17 00:00:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 736 bytes |
コンパイル時間 | 1,341 ms |
コンパイル使用メモリ | 168,524 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 02:37:09 |
合計ジャッジ時間 | 2,193 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n1; cin>>n1; int a[n1]; for (int i=0; i<n1; i++) cin>>a[i]; int n2; cin>>n2; int b[n2]; for (int i=0; i<n2; i++) cin>>b[i]; long long d = 1; long long n = 1; for (int i=0; i<n1; i++) { if (i == 0) { n *= a[i]; } else { d *= a[i]; } } for (int i=0; i<n2; i++) { if (i % 2 == 0) { d *= b[i]; } else { n *= b[i]; } } if (n < 0 && d < 0) { n *= -1; d *= -1; } else if (n > 0 && d < 0) { n *= -1; d *= -1; } long long x = 2; while (x <= abs(d) && x <= abs(n)) { while (d % x == 0 && n % x == 0) { d /= x; n /= x; } ++x; } cout<<n<<" "<<d<<endl; }