結果
| 問題 | No.751 Frac #2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-20 21:16:06 |
| 言語 | Java (openjdk 26.0.2.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 66 ms / 1,000 ms |
| + 319µs | |
| コード長 | 682 bytes |
| 記録 | |
| コンパイル時間 | 1,507 ms |
| コンパイル使用メモリ | 86,392 KB |
| 実行使用メモリ | 43,496 KB |
| 最終ジャッジ日時 | 2026-09-03 23:47:05 |
| 合計ジャッジ時間 | 6,196 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
import java.io.PrintWriter;
import java.util.Scanner;
class Main {
public static long gcd(long a, long b) {
return b != 0 ? gcd(b, a % b) : Math.abs(a);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
long A = sc.nextLong(), B = 1, tmp;
for (int i = 1; i < n; ++i) B *= sc.nextLong();
n = sc.nextInt();
for (int i = 0; i < n; ++i) {
if (i % 2 == 0) B *= sc.nextLong();
else A *= sc.nextLong();
}
sc.close();
if (B < 0) {
A = -A;
B = -B;
}
tmp = gcd(A, B);
pw.print(A / tmp + " " + B / tmp);
pw.close();
}
}