結果

問題 No.2 素因数ゲーム
コンテスト
ユーザー Grenache
提出日時 2016-03-05 10:34:34
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,065 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,850 ms
コンパイル使用メモリ 83,348 KB
実行使用メモリ 41,724 KB
最終ジャッジ日時 2026-06-01 09:36:03
合計ジャッジ時間 5,893 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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


public class Main_yukicoder2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        Map<Integer, Integer> pf = primeFactorization(n);

        int ret = 0;
        for (int e : pf.values()) {
        	ret ^= e;
        }

        if (ret == 0) {
        	System.out.println("Bob");
        } else {
        	System.out.println("Alice");
        }

        sc.close();
    }

    private static Map<Integer, Integer> primeFactorization(int n) {
    	Map<Integer, Integer> hm = new HashMap<Integer, Integer>();

    	int tmp = n;
    	for (int j = 2; j * j <= n; j++) {
    		while (tmp % j == 0) {
    			if (hm.containsKey(j)) {
    				hm.put(j, hm.get(j) + 1);
    			} else {
    				hm.put(j, 1);
    			}
    			tmp /= j;
    		}
    	}
    	if (tmp != 1) {
    		if (hm.containsKey(tmp)) {
    			hm.put(tmp, hm.get(tmp) + 1);
    		} else {
    			hm.put(tmp, 1);
    		}
    	}

    	return hm;
    }
}
0