結果
問題 |
No.751 Frac #2
|
ユーザー |
![]() |
提出日時 | 2018-11-14 18:57:51 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,042 bytes |
コンパイル時間 | 2,160 ms |
コンパイル使用メモリ | 76,788 KB |
実行使用メモリ | 42,548 KB |
最終ジャッジ日時 | 2024-12-24 13:46:44 |
合計ジャッジ時間 | 9,074 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 WA * 27 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = 0; long numerator = 1; long denominator = 1; n = sc.nextLong(); numerator = sc.nextLong(); for(long i=1;i<n;i++) { denominator *= sc.nextLong(); } n = sc.nextLong(); denominator *= sc.nextLong(); for(long i=1;i<n;i++) { numerator *= sc.nextLong(); } long gcf = calculateGcf(numerator, denominator); numerator /= gcf; denominator /= gcf; if(numerator < 0&&denominator < 0) { numerator*=-1; denominator*=-1; } else if(numerator >= 0&&denominator < 0){ numerator*=-1; denominator*=-1; } System.out.println(numerator+" "+denominator); } static long calculateGcf(long m, long n) { long s = 0; while(m % n != 0) { s = m; m = n; n = s % n; } return n; } }