結果

問題 No.1152 10億ゲーム
ユーザー ks2mks2m
提出日時 2020-08-07 23:13:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,883 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 76,296 KB
実行使用メモリ 72,408 KB
平均クエリ数 21.94
最終ジャッジ日時 2023-09-24 05:00:35
合計ジャッジ時間 15,125 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 196 ms
69,328 KB
testcase_01 AC 196 ms
68,872 KB
testcase_02 AC 215 ms
69,888 KB
testcase_03 AC 201 ms
68,100 KB
testcase_04 AC 197 ms
72,088 KB
testcase_05 AC 191 ms
70,920 KB
testcase_06 AC 208 ms
67,604 KB
testcase_07 AC 210 ms
68,652 KB
testcase_08 AC 182 ms
72,008 KB
testcase_09 AC 183 ms
71,200 KB
testcase_10 AC 195 ms
71,464 KB
testcase_11 AC 183 ms
69,404 KB
testcase_12 AC 211 ms
71,852 KB
testcase_13 AC 205 ms
69,916 KB
testcase_14 AC 199 ms
70,888 KB
testcase_15 AC 193 ms
69,672 KB
testcase_16 AC 183 ms
70,908 KB
testcase_17 AC 208 ms
71,372 KB
testcase_18 AC 200 ms
70,688 KB
testcase_19 AC 199 ms
70,352 KB
testcase_20 AC 181 ms
70,168 KB
testcase_21 AC 196 ms
71,692 KB
testcase_22 AC 194 ms
72,224 KB
testcase_23 AC 200 ms
70,616 KB
testcase_24 AC 198 ms
69,684 KB
testcase_25 AC 212 ms
72,276 KB
testcase_26 AC 204 ms
71,148 KB
testcase_27 AC 196 ms
68,960 KB
testcase_28 AC 210 ms
72,024 KB
testcase_29 AC 211 ms
71,284 KB
testcase_30 AC 196 ms
70,732 KB
testcase_31 AC 195 ms
69,120 KB
testcase_32 AC 207 ms
69,068 KB
testcase_33 AC 198 ms
69,520 KB
testcase_34 AC 199 ms
70,304 KB
testcase_35 AC 201 ms
70,580 KB
testcase_36 AC 200 ms
69,100 KB
testcase_37 AC 201 ms
70,724 KB
testcase_38 AC 189 ms
70,620 KB
testcase_39 AC 186 ms
70,940 KB
testcase_40 AC 201 ms
71,860 KB
testcase_41 AC 193 ms
70,828 KB
testcase_42 AC 205 ms
71,760 KB
testcase_43 AC 193 ms
70,652 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 200 ms
72,148 KB
testcase_47 AC 199 ms
72,120 KB
testcase_48 AC 181 ms
70,788 KB
testcase_49 AC 185 ms
71,096 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);

			try {
				y = sc.nextInt();
			} catch (Exception e) {
				break;
			}
			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