結果
| 問題 |
No.751 Frac #2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-28 14:01:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 139 ms / 1,000 ms |
| コード長 | 1,428 bytes |
| コンパイル時間 | 4,310 ms |
| コンパイル使用メモリ | 78,232 KB |
| 実行使用メモリ | 41,668 KB |
| 最終ジャッジ日時 | 2024-12-16 03:33:37 |
| 合計ジャッジ時間 | 9,772 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 |
ソースコード
import java.io.*;
import java.util.Scanner;
public class Main_yukicoder751 {
private static Scanner sc;
private static Printer pr;
private static void solve() {
int n1 = sc.nextInt();
int[] a = new int[n1];
for (int i = 0; i < n1; i++) {
a[i] = sc.nextInt();
}
int n2 = sc.nextInt();
int[] b = new int[n2];
for (int i = 0; i < n2; i++) {
b[i] = sc.nextInt();
}
long nu = a[0];
long de = 1;
for (int i = 1; i < n1; i++) {
de *= a[i];
}
long nub = b[n2 - 1];
long deb = 1;
for (int i = n2 - 2; i >= 0; i--) {
long tmp = deb;
deb = nub;
nub = b[i] * tmp;
}
long nuans = nu / gcd(nu, de);
long deans = de / gcd(nu, de);
nuans *= deb / gcd(nub, deb);
deans *= nub / gcd(nub, deb);
long gcd = gcd(nuans, deans);
nuans /= gcd;
deans /= gcd;
if (nuans < 0 && deans < 0) {
nuans = -nuans;
deans = -deans;
} else if (nuans > 0 && deans < 0) {
nuans = -nuans;
deans = -deans;
}
pr.printf("%d %d%n", nuans, deans);
}
static long gcd(long n, long m) {
if (m == 0) {
return n;
} else {
return gcd(m, n % m);
}
}
// ---------------------------------------------------
public static void main(String[] args) {
sc = new Scanner(System.in);
pr = new Printer(System.out);
solve();
pr.close();
sc.close();
}
static class Printer extends PrintWriter {
Printer(OutputStream out) {
super(out);
}
}
}