結果
問題 |
No.751 Frac #2
|
ユーザー |
![]() |
提出日時 | 2019-02-19 18:52:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 863 bytes |
コンパイル時間 | 1,515 ms |
コンパイル使用メモリ | 165,576 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 14:10:20 |
合計ジャッジ時間 | 2,593 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include<bits/stdc++.h> using namespace std; int gojoho(long long a, long long b){ if(a<0) a = -a; if(b<0) b = -b; while(1){ b %= a; if(b==0) break; else swap(a,b); } return a; } int main(){ long long Bunbo=1; long long Bunshi=1; int A; int B; int Na, Nb; int i; int Kouyakusu; scanf("%d", &Na); for(i=0; i<Na; i++){ scanf("%d", &A); if(i==0) Bunshi *= A; else Bunbo *= A; } scanf("%d", &Nb); for(i=0; i<Nb; i++){ scanf("%d", &B); if(i%2==0) Bunbo *= B; else Bunshi *= B; } Kouyakusu = gojoho(Bunbo,Bunshi); Bunbo /= Kouyakusu; Bunshi /= Kouyakusu; if(Bunbo<0){ Bunbo*=-1; Bunshi*=-1; } printf("%lld %lld", Bunshi, Bunbo); return 0; }