結果
| 問題 | 
                            No.751 Frac #2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-04-28 13:57:57 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,364 bytes | 
| コンパイル時間 | 3,496 ms | 
| コンパイル使用メモリ | 78,292 KB | 
| 実行使用メモリ | 41,668 KB | 
| 最終ジャッジ日時 | 2024-12-16 03:17:03 | 
| 合計ジャッジ時間 | 9,833 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 WA * 17 | 
ソースコード
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);
		
		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);
		}
	}
}