結果

問題 No.1152 10億ゲーム
ユーザー ks2mks2m
提出日時 2020-08-07 23:24:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,866 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 76,136 KB
実行使用メモリ 74,064 KB
平均クエリ数 22.70
最終ジャッジ日時 2023-09-24 05:05:13
合計ジャッジ時間 15,724 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 197 ms
71,632 KB
testcase_01 AC 191 ms
71,488 KB
testcase_02 AC 210 ms
73,972 KB
testcase_03 AC 203 ms
72,576 KB
testcase_04 AC 188 ms
71,632 KB
testcase_05 AC 209 ms
72,476 KB
testcase_06 AC 212 ms
71,884 KB
testcase_07 AC 213 ms
72,124 KB
testcase_08 AC 195 ms
72,192 KB
testcase_09 AC 197 ms
72,184 KB
testcase_10 AC 199 ms
71,628 KB
testcase_11 AC 198 ms
71,984 KB
testcase_12 AC 213 ms
69,976 KB
testcase_13 AC 214 ms
71,560 KB
testcase_14 AC 210 ms
71,844 KB
testcase_15 AC 208 ms
71,960 KB
testcase_16 AC 191 ms
72,336 KB
testcase_17 AC 209 ms
71,716 KB
testcase_18 AC 195 ms
67,056 KB
testcase_19 AC 217 ms
71,528 KB
testcase_20 AC 194 ms
69,868 KB
testcase_21 AC 195 ms
71,688 KB
testcase_22 AC 193 ms
72,040 KB
testcase_23 AC 198 ms
71,976 KB
testcase_24 AC 194 ms
69,712 KB
testcase_25 AC 211 ms
71,588 KB
testcase_26 AC 216 ms
71,924 KB
testcase_27 AC 214 ms
71,576 KB
testcase_28 AC 213 ms
71,472 KB
testcase_29 AC 214 ms
74,064 KB
testcase_30 AC 216 ms
72,536 KB
testcase_31 AC 212 ms
71,376 KB
testcase_32 AC 214 ms
72,044 KB
testcase_33 AC 219 ms
71,920 KB
testcase_34 AC 209 ms
72,020 KB
testcase_35 AC 205 ms
71,424 KB
testcase_36 AC 213 ms
71,980 KB
testcase_37 AC 209 ms
72,200 KB
testcase_38 AC 200 ms
71,184 KB
testcase_39 AC 201 ms
71,356 KB
testcase_40 AC 199 ms
71,856 KB
testcase_41 AC 202 ms
70,288 KB
testcase_42 AC 210 ms
70,332 KB
testcase_43 AC 210 ms
71,392 KB
testcase_44 AC 209 ms
72,176 KB
testcase_45 AC 212 ms
70,456 KB
testcase_46 AC 200 ms
69,548 KB
testcase_47 AC 198 ms
71,804 KB
testcase_48 AC 190 ms
71,928 KB
testcase_49 AC 198 ms
71,220 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 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