結果

問題 No.25 有限小数
ユーザー GrenacheGrenache
提出日時 2016-03-11 20:33:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 1,058 bytes
コンパイル時間 3,303 ms
コンパイル使用メモリ 77,584 KB
実行使用メモリ 54,284 KB
最終ジャッジ日時 2024-04-27 17:14:16
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
53,648 KB
testcase_01 AC 118 ms
54,000 KB
testcase_02 AC 115 ms
53,840 KB
testcase_03 AC 112 ms
53,996 KB
testcase_04 AC 113 ms
53,216 KB
testcase_05 AC 111 ms
54,112 KB
testcase_06 AC 110 ms
54,092 KB
testcase_07 AC 113 ms
53,860 KB
testcase_08 AC 110 ms
53,776 KB
testcase_09 AC 116 ms
54,116 KB
testcase_10 AC 118 ms
53,988 KB
testcase_11 AC 102 ms
52,764 KB
testcase_12 AC 112 ms
53,540 KB
testcase_13 AC 101 ms
52,652 KB
testcase_14 AC 114 ms
53,672 KB
testcase_15 AC 114 ms
53,972 KB
testcase_16 AC 100 ms
52,600 KB
testcase_17 AC 102 ms
52,840 KB
testcase_18 AC 123 ms
53,992 KB
testcase_19 AC 104 ms
52,832 KB
testcase_20 AC 107 ms
53,488 KB
testcase_21 AC 102 ms
52,796 KB
testcase_22 AC 108 ms
53,488 KB
testcase_23 AC 114 ms
53,660 KB
testcase_24 AC 108 ms
52,572 KB
testcase_25 AC 113 ms
53,788 KB
testcase_26 AC 110 ms
54,284 KB
testcase_27 AC 96 ms
52,568 KB
testcase_28 AC 110 ms
53,856 KB
testcase_29 AC 103 ms
52,528 KB
testcase_30 AC 110 ms
53,840 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