結果
| 問題 |
No.751 Frac #2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-09 21:46:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 589 bytes |
| コンパイル時間 | 613 ms |
| コンパイル使用メモリ | 65,252 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-21 05:48:49 |
| 合計ジャッジ時間 | 1,571 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
#include<iostream>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
return b == 0 ? a : gcd(b, a%b);
}
int main(){
int n, m, a;
ll child = 1, mother = 1;
cin >> n >> child;
for(int i = 1; i < n; i++) cin >> a, mother *= a;
cin >> m;
for(int i = 0; i < m; i++){
cin >> a;
if(i % 2 == 0) mother *= a;
else child *= a;
}
if(mother < 0) mother *= -1, child *= -1;
ll g = gcd(abs(child), mother);
child /= g;
mother /= g;
cout << child << " " << mother << endl;
return 0;
}