結果

問題 No.1152 10億ゲーム
ユーザー ks2mks2m
提出日時 2020-08-07 23:11:09
言語 Java19
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,937 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 75,904 KB
実行使用メモリ 72,668 KB
平均クエリ数 21.94
最終ジャッジ日時 2023-09-24 04:59:14
合計ジャッジ時間 14,731 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
70,824 KB
testcase_01 AC 171 ms
70,664 KB
testcase_02 AC 201 ms
71,880 KB
testcase_03 AC 198 ms
71,980 KB
testcase_04 AC 171 ms
69,060 KB
testcase_05 AC 202 ms
71,848 KB
testcase_06 AC 202 ms
71,192 KB
testcase_07 AC 201 ms
72,276 KB
testcase_08 AC 180 ms
71,084 KB
testcase_09 AC 180 ms
70,904 KB
testcase_10 AC 187 ms
72,168 KB
testcase_11 AC 191 ms
71,916 KB
testcase_12 AC 200 ms
70,904 KB
testcase_13 AC 207 ms
70,640 KB
testcase_14 AC 193 ms
69,584 KB
testcase_15 AC 182 ms
69,764 KB
testcase_16 AC 180 ms
70,828 KB
testcase_17 AC 197 ms
69,044 KB
testcase_18 AC 193 ms
71,020 KB
testcase_19 AC 186 ms
69,116 KB
testcase_20 AC 187 ms
71,452 KB
testcase_21 AC 177 ms
69,960 KB
testcase_22 AC 182 ms
70,220 KB
testcase_23 AC 176 ms
69,576 KB
testcase_24 AC 204 ms
71,488 KB
testcase_25 AC 206 ms
71,980 KB
testcase_26 AC 208 ms
72,204 KB
testcase_27 AC 202 ms
69,416 KB
testcase_28 AC 203 ms
70,868 KB
testcase_29 AC 206 ms
71,972 KB
testcase_30 AC 198 ms
69,012 KB
testcase_31 AC 197 ms
69,664 KB
testcase_32 AC 189 ms
70,564 KB
testcase_33 AC 189 ms
71,164 KB
testcase_34 AC 207 ms
71,840 KB
testcase_35 AC 200 ms
71,236 KB
testcase_36 AC 199 ms
71,148 KB
testcase_37 AC 198 ms
71,268 KB
testcase_38 AC 183 ms
69,272 KB
testcase_39 AC 192 ms
71,852 KB
testcase_40 AC 191 ms
70,428 KB
testcase_41 AC 196 ms
72,500 KB
testcase_42 AC 190 ms
69,488 KB
testcase_43 AC 202 ms
71,680 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 196 ms
71,908 KB
testcase_47 AC 185 ms
69,632 KB
testcase_48 AC 173 ms
70,844 KB
testcase_49 AC 197 ms
72,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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