結果

問題 No.1152 10億ゲーム
ユーザー ks2mks2m
提出日時 2020-08-07 23:08:39
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,830 bytes
コンパイル時間 3,294 ms
コンパイル使用メモリ 76,008 KB
実行使用メモリ 72,772 KB
平均クエリ数 21.94
最終ジャッジ日時 2023-09-24 04:57:52
合計ジャッジ時間 15,638 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 184 ms
71,792 KB
testcase_01 AC 178 ms
71,128 KB
testcase_02 AC 193 ms
71,860 KB
testcase_03 AC 190 ms
71,960 KB
testcase_04 AC 177 ms
71,840 KB
testcase_05 AC 194 ms
71,672 KB
testcase_06 AC 191 ms
71,372 KB
testcase_07 AC 197 ms
72,172 KB
testcase_08 AC 180 ms
71,924 KB
testcase_09 AC 183 ms
72,080 KB
testcase_10 AC 177 ms
71,564 KB
testcase_11 AC 183 ms
71,824 KB
testcase_12 AC 192 ms
71,700 KB
testcase_13 AC 193 ms
72,364 KB
testcase_14 AC 193 ms
71,864 KB
testcase_15 AC 190 ms
71,728 KB
testcase_16 AC 176 ms
71,668 KB
testcase_17 AC 193 ms
71,576 KB
testcase_18 AC 197 ms
70,116 KB
testcase_19 AC 194 ms
72,360 KB
testcase_20 AC 182 ms
72,144 KB
testcase_21 AC 183 ms
71,776 KB
testcase_22 AC 184 ms
71,456 KB
testcase_23 AC 186 ms
71,888 KB
testcase_24 AC 210 ms
71,308 KB
testcase_25 AC 198 ms
70,300 KB
testcase_26 AC 203 ms
71,720 KB
testcase_27 AC 198 ms
70,496 KB
testcase_28 AC 193 ms
71,428 KB
testcase_29 AC 197 ms
72,260 KB
testcase_30 AC 190 ms
69,592 KB
testcase_31 AC 198 ms
71,228 KB
testcase_32 AC 194 ms
71,488 KB
testcase_33 AC 195 ms
71,724 KB
testcase_34 AC 198 ms
72,096 KB
testcase_35 AC 202 ms
71,672 KB
testcase_36 AC 195 ms
72,076 KB
testcase_37 AC 190 ms
71,960 KB
testcase_38 AC 181 ms
71,540 KB
testcase_39 AC 191 ms
71,940 KB
testcase_40 AC 189 ms
71,636 KB
testcase_41 AC 185 ms
71,892 KB
testcase_42 AC 192 ms
71,384 KB
testcase_43 AC 197 ms
71,912 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 184 ms
72,564 KB
testcase_47 AC 186 ms
72,436 KB
testcase_48 AC 177 ms
71,972 KB
testcase_49 AC 182 ms
71,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();

		Map<Integer, Integer> mapx = bunkai(x);
		int x2 = mapx.getOrDefault(2, 0);
		int x5 = mapx.getOrDefault(5, 0);
		Map<Integer, Integer> mapy = bunkai(y);
		int y2 = mapy.getOrDefault(2, 0);
		int y5 = mapy.getOrDefault(5, 0);

		for (int i = 0; i < 35; i++) {
			if ((x2 + x5 - y2 - y5) % 2 == 0) {
				if (x5 < y5) {
					x5++;
				} else if (x2 < 7) {
					x2++;
				} else {
					x5++;
				}
			} else if (x5 < y5) {
				x5++;
			} else if (x2 < y2) {
				x2++;
			} else {
				if (x2 - y2 > x5 - y5) {
					x2--;
				} else {
					x5--;
				}
			}
			x = calc(x2, x5);
			System.out.println(x);
			if (x == y) {
				break;
			}
			mapx = bunkai(x);
			x2 = mapx.getOrDefault(2, 0);
			x5 = mapx.getOrDefault(5, 0);

			y = sc.nextInt();
			if (x == y) {
				break;
			}
			mapy = bunkai(y);
			y2 = mapy.getOrDefault(2, 0);
			y5 = mapy.getOrDefault(5, 0);
		}
		sc.close();
	}

	static int calc(int x2, int x5) {
		return Math.min(power(2, x2) * power(5, x5), 1000000000);
	}

	static int power(int x, int n) {
		if (n == 0) {
			return 1;
		}
		int val = power(x, n / 2);
		val = val * val;
		if (n % 2 == 1) {
			val = val * x;
		}
		return val;
	}

	static Map<Integer, Integer> bunkai(int n) {
		Map<Integer, Integer> soinsu = new HashMap<>();
		int end = (int) Math.sqrt(n);
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}
0