結果

問題 No.25 有限小数
ユーザー GrenacheGrenache
提出日時 2016-03-11 20:33:14
言語 Java19
(openjdk 21)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 3,483 ms
コンパイル使用メモリ 74,900 KB
実行使用メモリ 55,896 KB
最終ジャッジ日時 2023-08-09 22:58:41
合計ジャッジ時間 8,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,280 KB
testcase_01 AC 125 ms
55,592 KB
testcase_02 AC 124 ms
55,280 KB
testcase_03 AC 126 ms
55,716 KB
testcase_04 AC 124 ms
55,896 KB
testcase_05 AC 126 ms
55,872 KB
testcase_06 AC 124 ms
55,536 KB
testcase_07 AC 122 ms
55,520 KB
testcase_08 AC 122 ms
55,744 KB
testcase_09 AC 123 ms
55,488 KB
testcase_10 AC 121 ms
55,280 KB
testcase_11 AC 125 ms
55,552 KB
testcase_12 AC 121 ms
55,616 KB
testcase_13 AC 122 ms
55,284 KB
testcase_14 AC 121 ms
55,888 KB
testcase_15 AC 121 ms
55,632 KB
testcase_16 AC 122 ms
55,392 KB
testcase_17 AC 123 ms
55,396 KB
testcase_18 AC 125 ms
55,556 KB
testcase_19 AC 122 ms
55,580 KB
testcase_20 AC 123 ms
55,776 KB
testcase_21 AC 124 ms
55,464 KB
testcase_22 AC 125 ms
55,564 KB
testcase_23 AC 122 ms
55,376 KB
testcase_24 AC 120 ms
55,288 KB
testcase_25 AC 122 ms
55,612 KB
testcase_26 AC 124 ms
55,632 KB
testcase_27 AC 125 ms
55,644 KB
testcase_28 AC 119 ms
55,624 KB
testcase_29 AC 119 ms
53,472 KB
testcase_30 AC 120 ms
55,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder25 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        long m = sc.nextLong();

        long gcd = gcd(n, m);

        n /= gcd;
        m /= gcd;

        int cnt2 = 0;
        while (m % 2 == 0) {
        	cnt2++;
        	m /= 2;
        }
        int cnt5 = 0;
        while (m % 5 == 0) {
        	cnt5++;
        	m /= 5;
        }

        while (n % 10 == 0) {
        	n /= 10;
        }
        n %= 10;

        if (m != 1) {
        	System.out.println(-1);
        } else if (cnt2 == cnt5) {
        	System.out.println(n);
        } else if (cnt2 > cnt5) {
        	System.out.println(5);
        } else {
        	long tmp = 1;
        	for (int i = 0; i < cnt5 - cnt2; i++) {
        		tmp *= 2;
        	}
        	System.out.println(tmp * n % 10);
        }

        sc.close();
    }

	private static long gcd(long n, long m) {
		if (m == 0) {
			return n;
		} else {
			return gcd(m, n % m);
		}
	}
}
0