結果

問題 No.25 有限小数
ユーザー kano_townkano_town
提出日時 2014-11-22 21:05:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 3,280 ms
コンパイル使用メモリ 72,684 KB
実行使用メモリ 56,416 KB
最終ジャッジ日時 2023-08-30 22:13:37
合計ジャッジ時間 8,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,496 KB
testcase_01 AC 121 ms
56,068 KB
testcase_02 AC 122 ms
55,888 KB
testcase_03 AC 123 ms
56,100 KB
testcase_04 AC 124 ms
55,732 KB
testcase_05 AC 124 ms
55,772 KB
testcase_06 AC 122 ms
56,160 KB
testcase_07 AC 122 ms
56,268 KB
testcase_08 AC 122 ms
55,852 KB
testcase_09 AC 121 ms
56,188 KB
testcase_10 AC 122 ms
56,024 KB
testcase_11 AC 123 ms
56,032 KB
testcase_12 WA -
testcase_13 AC 120 ms
56,276 KB
testcase_14 AC 119 ms
55,836 KB
testcase_15 AC 120 ms
55,780 KB
testcase_16 AC 122 ms
55,844 KB
testcase_17 AC 119 ms
55,896 KB
testcase_18 AC 121 ms
55,736 KB
testcase_19 AC 120 ms
56,104 KB
testcase_20 AC 120 ms
55,512 KB
testcase_21 AC 120 ms
56,064 KB
testcase_22 AC 119 ms
56,416 KB
testcase_23 AC 119 ms
56,036 KB
testcase_24 AC 119 ms
55,936 KB
testcase_25 AC 118 ms
55,956 KB
testcase_26 AC 118 ms
55,836 KB
testcase_27 AC 118 ms
55,992 KB
testcase_28 AC 117 ms
55,612 KB
testcase_29 AC 116 ms
56,280 KB
testcase_30 AC 119 ms
55,964 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 /= 10;

		N = N % 10 == 0 ? 1 : N % 10;
		while (M % 5L == 0L) {
			M /= 5;
			N = N * 2 % 10;
		}
		while (M % 2L == 0L) {
			M /= 2;
			N = 5;
		}
		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