結果

問題 No.1152 10億ゲーム
ユーザー ks2mks2m
提出日時 2020-08-07 23:15:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,937 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 75,976 KB
実行使用メモリ 72,720 KB
平均クエリ数 21.94
最終ジャッジ日時 2023-09-24 05:01:28
合計ジャッジ時間 15,382 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 196 ms
71,628 KB
testcase_01 AC 177 ms
71,396 KB
testcase_02 AC 209 ms
71,840 KB
testcase_03 AC 211 ms
71,908 KB
testcase_04 AC 191 ms
71,908 KB
testcase_05 AC 205 ms
72,720 KB
testcase_06 AC 196 ms
71,372 KB
testcase_07 AC 211 ms
70,992 KB
testcase_08 AC 192 ms
70,080 KB
testcase_09 AC 176 ms
69,568 KB
testcase_10 AC 195 ms
71,864 KB
testcase_11 AC 193 ms
72,204 KB
testcase_12 AC 200 ms
70,640 KB
testcase_13 AC 197 ms
70,196 KB
testcase_14 AC 209 ms
71,912 KB
testcase_15 AC 197 ms
71,160 KB
testcase_16 AC 194 ms
71,656 KB
testcase_17 AC 211 ms
71,472 KB
testcase_18 AC 207 ms
70,424 KB
testcase_19 AC 210 ms
72,256 KB
testcase_20 AC 193 ms
69,688 KB
testcase_21 AC 192 ms
69,956 KB
testcase_22 AC 195 ms
71,752 KB
testcase_23 AC 183 ms
69,644 KB
testcase_24 AC 216 ms
72,100 KB
testcase_25 AC 202 ms
70,324 KB
testcase_26 AC 207 ms
69,944 KB
testcase_27 AC 192 ms
69,676 KB
testcase_28 AC 209 ms
71,208 KB
testcase_29 AC 209 ms
71,936 KB
testcase_30 AC 196 ms
71,992 KB
testcase_31 AC 198 ms
70,360 KB
testcase_32 AC 202 ms
71,156 KB
testcase_33 AC 193 ms
69,812 KB
testcase_34 AC 196 ms
69,468 KB
testcase_35 AC 195 ms
69,244 KB
testcase_36 AC 198 ms
69,348 KB
testcase_37 AC 213 ms
72,236 KB
testcase_38 AC 188 ms
70,632 KB
testcase_39 AC 188 ms
71,056 KB
testcase_40 AC 186 ms
69,504 KB
testcase_41 AC 187 ms
69,344 KB
testcase_42 AC 193 ms
70,356 KB
testcase_43 AC 207 ms
71,844 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 202 ms
72,040 KB
testcase_47 AC 199 ms
72,248 KB
testcase_48 AC 176 ms
70,488 KB
testcase_49 AC 180 ms
69,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
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 (NoSuchElementException 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