結果
問題 |
No.751 Frac #2
|
ユーザー |
|
提出日時 | 2018-11-22 12:40:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 758 bytes |
コンパイル時間 | 549 ms |
コンパイル使用メモリ | 54,360 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 16:20:48 |
合計ジャッジ時間 | 1,902 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 4 WA * 32 |
ソースコード
#include <iostream> #include <string> using namespace std; int gcf(int a, int b) { if (b == 0) { return a; } return gcf(b, a % b); } int main(void) { int A[20], B[20]; int n1, n2; cin >> n1; for (int i = 0; i < n1; ++i) { cin >> A[i]; } cin >> n2; for (int i = 0; i < n2; i++) { cin >> B[i]; } int f1 = A[0]; int f2 = B[0]; int sum1 = 1, sum2 = 1; for (int i = 1; i < n1; ++i) { sum1 *= A[i]; } for (int i = 1; i < n2; ++i) { sum2 *= B[i]; } int deno = sum1 * f2; int nume = sum2 * f1; int g = gcf(deno, nume); nume = (deno < 0) ? -nume : nume; deno = (deno < 0) ? -deno : deno; cout << nume / g << " " << deno / g << endl; }