結果
問題 | No.2 素因数ゲーム |
ユーザー |
|
提出日時 | 2016-03-05 10:34:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 156 ms / 5,000 ms |
コード長 | 1,065 bytes |
コンパイル時間 | 4,664 ms |
コンパイル使用メモリ | 80,152 KB |
実行使用メモリ | 41,304 KB |
最終ジャッジ日時 | 2024-12-26 12:21:59 |
合計ジャッジ時間 | 10,090 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
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; } }