結果

問題 No.25 有限小数
ユーザー htensaihtensai
提出日時 2020-01-15 09:13:26
言語 Java19
(openjdk 21)
結果
TLE  
実行時間 -
コード長 964 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 73,088 KB
実行使用メモリ 57,848 KB
最終ジャッジ日時 2023-08-29 22:13:24
合計ジャッジ時間 14,749 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,852 KB
testcase_01 AC 116 ms
56,164 KB
testcase_02 AC 114 ms
55,348 KB
testcase_03 AC 118 ms
55,912 KB
testcase_04 AC 117 ms
57,848 KB
testcase_05 AC 120 ms
55,508 KB
testcase_06 AC 115 ms
56,188 KB
testcase_07 AC 114 ms
56,052 KB
testcase_08 AC 113 ms
55,696 KB
testcase_09 AC 116 ms
55,812 KB
testcase_10 AC 114 ms
55,912 KB
testcase_11 AC 115 ms
55,908 KB
testcase_12 AC 116 ms
55,912 KB
testcase_13 AC 118 ms
56,364 KB
testcase_14 AC 114 ms
55,844 KB
testcase_15 AC 113 ms
56,240 KB
testcase_16 AC 114 ms
55,960 KB
testcase_17 AC 115 ms
55,760 KB
testcase_18 AC 117 ms
55,624 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigInteger n = new BigInteger(sc.next());
        BigInteger m = new BigInteger(sc.next());
        HashSet<BigInteger> set = new HashSet<>();
        while (true) {
            BigInteger mod = n.mod(m);
            if (mod.equals(BigInteger.ZERO)) {
                System.out.println(getLastNum(n.divide(m)));
                return;
            }
            n = mod;
            if (set.contains(n)) {
                System.out.println(-1);
                return;
            }
            set.add(n);
            n = n.multiply(BigInteger.TEN);
        }
    }
    
    static long getLastNum(BigInteger b) {
        long x = b.longValue();
        while (x > 0) {
            if (x % 10 != 0) {
                return x % 10;
            }
            x /= 10;
        }
        return 0;
    }
}
0