結果

問題 No.25 有限小数
ユーザー tentententen
提出日時 2020-10-22 17:00:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 1,155 bytes
コンパイル時間 2,429 ms
コンパイル使用メモリ 73,460 KB
実行使用メモリ 56,304 KB
最終ジャッジ日時 2023-09-28 14:41:25
合計ジャッジ時間 8,116 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,800 KB
testcase_01 AC 129 ms
55,784 KB
testcase_02 AC 128 ms
55,540 KB
testcase_03 AC 129 ms
55,540 KB
testcase_04 AC 131 ms
56,092 KB
testcase_05 AC 130 ms
55,928 KB
testcase_06 AC 133 ms
55,828 KB
testcase_07 AC 133 ms
55,740 KB
testcase_08 AC 134 ms
55,728 KB
testcase_09 AC 130 ms
56,032 KB
testcase_10 AC 128 ms
55,636 KB
testcase_11 AC 125 ms
55,516 KB
testcase_12 AC 129 ms
55,720 KB
testcase_13 AC 127 ms
56,004 KB
testcase_14 AC 131 ms
55,900 KB
testcase_15 AC 129 ms
55,676 KB
testcase_16 AC 132 ms
55,712 KB
testcase_17 AC 127 ms
55,764 KB
testcase_18 AC 129 ms
55,600 KB
testcase_19 AC 133 ms
55,820 KB
testcase_20 AC 127 ms
55,656 KB
testcase_21 AC 129 ms
55,764 KB
testcase_22 AC 129 ms
55,908 KB
testcase_23 AC 126 ms
56,304 KB
testcase_24 AC 127 ms
55,988 KB
testcase_25 AC 127 ms
55,724 KB
testcase_26 AC 130 ms
55,464 KB
testcase_27 AC 130 ms
55,728 KB
testcase_28 AC 129 ms
55,736 KB
testcase_29 AC 128 ms
55,764 KB
testcase_30 AC 128 ms
55,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long gcd = getGCD(n, m);
        n /= gcd;
        m /= gcd;
        long x = m;
        int twoCount = 0;
        while (x % 2 == 0){
            x /= 2;
            twoCount++;
        }
        int fiveCount = 0;
        while (x % 5 == 0) {
            x /= 5;
            fiveCount++;
        }
        if (x != 1) {
            System.out.println(-1);
            return;
        }
        while (n % 10 == 0) {
            n /= 10;
        }
        n %= 10;
        if (twoCount > fiveCount) {
            System.out.println(5);
        } else {
            fiveCount -= twoCount;
            for (int i = 0; i < fiveCount; i++) {
                n *= 10;
                n /= 5;
                n %= 10;
            }
            System.out.println(n);
        }
     }
     
     static long getGCD(long x, long y) {
         if (x % y == 0) {
             return y;
         } else {
             return getGCD(y, x % y);
         }
     }
}
0