結果

問題 No.25 有限小数
ユーザー kano_townkano_town
提出日時 2014-11-22 21:12:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 119 ms / 5,000 ms
コード長 782 bytes
コンパイル時間 2,884 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 41,656 KB
最終ジャッジ日時 2024-04-27 17:07:35
合計ジャッジ時間 7,068 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
40,136 KB
testcase_01 AC 114 ms
41,084 KB
testcase_02 AC 113 ms
41,108 KB
testcase_03 AC 110 ms
41,204 KB
testcase_04 AC 108 ms
40,608 KB
testcase_05 AC 112 ms
41,440 KB
testcase_06 AC 94 ms
39,880 KB
testcase_07 AC 110 ms
41,148 KB
testcase_08 AC 108 ms
41,108 KB
testcase_09 AC 109 ms
41,168 KB
testcase_10 AC 119 ms
41,396 KB
testcase_11 AC 113 ms
41,400 KB
testcase_12 AC 102 ms
40,080 KB
testcase_13 AC 101 ms
40,208 KB
testcase_14 AC 109 ms
41,216 KB
testcase_15 AC 101 ms
40,036 KB
testcase_16 AC 102 ms
40,228 KB
testcase_17 AC 101 ms
40,192 KB
testcase_18 AC 110 ms
41,652 KB
testcase_19 AC 104 ms
40,456 KB
testcase_20 AC 98 ms
40,200 KB
testcase_21 AC 106 ms
41,140 KB
testcase_22 AC 106 ms
41,448 KB
testcase_23 AC 111 ms
41,420 KB
testcase_24 AC 107 ms
41,656 KB
testcase_25 AC 106 ms
40,936 KB
testcase_26 AC 108 ms
41,068 KB
testcase_27 AC 104 ms
40,092 KB
testcase_28 AC 108 ms
40,572 KB
testcase_29 AC 105 ms
41,072 KB
testcase_30 AC 95 ms
39,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder25 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		long div;
		
		while ((div = gcd(N, M)) != 1) {
			N /= div;
			M /= div;
		}
		
		while (M % 10L == 0L) M /= 10L;
		if (M == 1) while (N % 10L == 0L) N /= 10L;

		N = N % 10L == 0L ? 1L : N % 10L;
		while (M % 5L == 0L) {
			M /= 5;
			N = N * 2L % 10L;
		}
		while (M % 2L == 0L) {
			M /= 2L;
			N = 5L;
		}
		N = M == 1 ? N : -1;
		System.out.println(N);

	}

	static long gcd(long a, long b) {
		long c, tmp;

		if (a < b) {
			tmp = a;
			a = b;
			b = tmp;
		}

		while (b != 0) {
			c = a % b;
			a = b;
			b = c;
		}
		return a;
	}
}
0