結果

問題 No.25 有限小数
ユーザー KilisameKilisame
提出日時 2016-06-16 15:20:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 1,150 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 75,220 KB
実行使用メモリ 57,936 KB
最終ジャッジ日時 2023-08-09 22:59:24
合計ジャッジ時間 6,972 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,648 KB
testcase_01 AC 114 ms
55,560 KB
testcase_02 AC 116 ms
55,720 KB
testcase_03 AC 118 ms
57,936 KB
testcase_04 AC 117 ms
55,904 KB
testcase_05 AC 118 ms
55,772 KB
testcase_06 AC 117 ms
55,756 KB
testcase_07 AC 116 ms
55,516 KB
testcase_08 AC 120 ms
56,108 KB
testcase_09 AC 118 ms
55,500 KB
testcase_10 AC 118 ms
55,492 KB
testcase_11 AC 116 ms
55,464 KB
testcase_12 AC 116 ms
55,492 KB
testcase_13 AC 119 ms
54,176 KB
testcase_14 AC 119 ms
55,948 KB
testcase_15 AC 116 ms
55,456 KB
testcase_16 AC 119 ms
56,036 KB
testcase_17 AC 121 ms
56,008 KB
testcase_18 AC 121 ms
55,724 KB
testcase_19 AC 119 ms
55,408 KB
testcase_20 AC 115 ms
55,328 KB
testcase_21 AC 117 ms
55,940 KB
testcase_22 AC 120 ms
55,736 KB
testcase_23 AC 116 ms
55,704 KB
testcase_24 AC 113 ms
55,784 KB
testcase_25 AC 113 ms
55,556 KB
testcase_26 AC 116 ms
55,584 KB
testcase_27 AC 115 ms
55,472 KB
testcase_28 AC 117 ms
55,684 KB
testcase_29 AC 116 ms
55,584 KB
testcase_30 AC 114 ms
55,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    private static long n;

    private static long m;

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        n = Long.parseLong(cin.next());
        m = Long.parseLong(cin.next());
        cin.close();
        calculate();
    }

    private static void calculate() {
        long target = m;
        while (target % 2 == 0) {
            target /= 2;
        }
        while (target % 5 == 0) {
            target /= 5;
        }
        if (n % target != 0) {
            System.out.println(-1);
        } else {
            String resultStr = new BigDecimal(n).divide(new BigDecimal(m)).toString();
            if (resultStr.contains("E")) {
                resultStr = resultStr.substring(0, resultStr.indexOf("E"));
            }
            char[] charArray = resultStr.toCharArray();
            for (int i = charArray.length - 1; i >= 0; i--) {
                if (charArray[i] != '0') {
                    System.out.println(charArray[i]);
                    break;
                }
            }
        }
    }
}
0