結果

問題 No.25 有限小数
ユーザー kano_townkano_town
提出日時 2014-11-22 21:12:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 782 bytes
コンパイル時間 3,337 ms
コンパイル使用メモリ 72,860 KB
実行使用メモリ 56,288 KB
最終ジャッジ日時 2023-08-09 22:50:46
合計ジャッジ時間 8,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,660 KB
testcase_01 AC 124 ms
56,000 KB
testcase_02 AC 127 ms
55,864 KB
testcase_03 AC 125 ms
55,716 KB
testcase_04 AC 128 ms
55,900 KB
testcase_05 AC 125 ms
56,044 KB
testcase_06 AC 128 ms
55,624 KB
testcase_07 AC 125 ms
55,768 KB
testcase_08 AC 124 ms
55,724 KB
testcase_09 AC 124 ms
56,288 KB
testcase_10 AC 124 ms
56,100 KB
testcase_11 AC 123 ms
55,744 KB
testcase_12 AC 124 ms
55,776 KB
testcase_13 AC 126 ms
56,148 KB
testcase_14 AC 125 ms
55,980 KB
testcase_15 AC 125 ms
55,796 KB
testcase_16 AC 125 ms
56,132 KB
testcase_17 AC 125 ms
53,964 KB
testcase_18 AC 125 ms
55,960 KB
testcase_19 AC 124 ms
55,872 KB
testcase_20 AC 126 ms
55,872 KB
testcase_21 AC 125 ms
56,148 KB
testcase_22 AC 125 ms
56,012 KB
testcase_23 AC 124 ms
55,916 KB
testcase_24 AC 125 ms
55,996 KB
testcase_25 AC 126 ms
54,024 KB
testcase_26 AC 126 ms
55,896 KB
testcase_27 AC 126 ms
55,772 KB
testcase_28 AC 125 ms
55,824 KB
testcase_29 AC 124 ms
55,784 KB
testcase_30 AC 125 ms
56,020 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