結果

問題 No.25 有限小数
ユーザー KilisameKilisame
提出日時 2016-06-16 15:11:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 75,576 KB
実行使用メモリ 41,900 KB
最終ジャッジ日時 2024-04-17 22:50:36
合計ジャッジ時間 6,627 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
41,672 KB
testcase_01 AC 97 ms
41,508 KB
testcase_02 AC 98 ms
41,392 KB
testcase_03 AC 123 ms
41,416 KB
testcase_04 WA -
testcase_05 AC 107 ms
40,472 KB
testcase_06 AC 102 ms
41,648 KB
testcase_07 AC 105 ms
41,080 KB
testcase_08 AC 111 ms
41,548 KB
testcase_09 AC 126 ms
41,476 KB
testcase_10 AC 108 ms
41,584 KB
testcase_11 AC 99 ms
41,456 KB
testcase_12 AC 119 ms
41,900 KB
testcase_13 AC 127 ms
41,372 KB
testcase_14 AC 120 ms
41,508 KB
testcase_15 AC 115 ms
41,700 KB
testcase_16 AC 116 ms
41,404 KB
testcase_17 AC 114 ms
41,492 KB
testcase_18 AC 114 ms
40,520 KB
testcase_19 AC 120 ms
41,368 KB
testcase_20 AC 115 ms
41,132 KB
testcase_21 AC 128 ms
41,460 KB
testcase_22 AC 130 ms
41,784 KB
testcase_23 AC 129 ms
41,256 KB
testcase_24 AC 121 ms
41,372 KB
testcase_25 AC 120 ms
41,396 KB
testcase_26 AC 107 ms
41,456 KB
testcase_27 AC 125 ms
41,192 KB
testcase_28 AC 114 ms
40,992 KB
testcase_29 AC 122 ms
41,552 KB
testcase_30 AC 114 ms
41,380 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();
            char[] charArray = resultStr.toCharArray();
            for (int i = charArray.length - 1; i >= 0; i--) {
                if (charArray[i] != '0') {
                    System.out.println(charArray[i]);
                    break;
                }
            }
        }
    }
}
0