結果
問題 |
No.751 Frac #2
|
ユーザー |
![]() |
提出日時 | 2018-11-15 16:05:55 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 797 bytes |
コンパイル時間 | 2,553 ms |
コンパイル使用メモリ | 76,644 KB |
実行使用メモリ | 42,432 KB |
最終ジャッジ日時 | 2024-12-24 13:57:32 |
合計ジャッジ時間 | 10,704 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | WA * 36 |
ソースコード
import java.util.*; public class Main { static Scanner sc; static int n; static long numerator; static long denominator; public static void main(String[] args) { sc = new Scanner(System.in); numerator = 1; denominator = 1; n = sc.nextInt(); input(0, n); input(n, sc.nextInt()); long gcf = calculateGcf(numerator, denominator); numerator /= gcf; denominator /= gcf; System.out.println(numerator+" "+denominator); } static void input(int l, int m) { for(int i=l;i<m;i++) { if(i % 2 != 0) { numerator *= sc.nextInt(); } else { denominator *= sc.nextInt(); } } } static long calculateGcf(long m, long n) { if(m == 0 || n == 0) { return 1; } long s = 0; while(m % n != 0) { s = m; m = n; n = s % n; } return n; } }