結果
問題 |
No.2 素因数ゲーム
|
ユーザー |
![]() |
提出日時 | 2016-01-30 23:50:46 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,823 bytes |
コンパイル時間 | 4,873 ms |
コンパイル使用メモリ | 77,864 KB |
実行使用メモリ | 151,744 KB |
最終ジャッジ日時 | 2024-09-21 19:36:21 |
合計ジャッジ時間 | 28,372 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 WA * 8 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(stdReader.readLine()); boolean[] dp = new boolean[N+1]; ArrayList<Integer> primeList = new ArrayList<>(); HashMap<Integer , Integer> hashMap = new HashMap<>(); Arrays.fill(dp, true); dp[0] = false; dp[1] = false; for(int i=2;i*i<=N;i++){ if(dp[i]){ for(int j=2;j*i<=N;j++){ dp[i*j] = false; } } } int index = 2; while(N>1){ if(dp[index] && N % index == 0){ if(!hashMap.containsKey(index)){ hashMap.put(index, 1); primeList.add(index); }else{ hashMap.put(index, hashMap.get(index)+1); } N /= index; }else{ index++; } } int mult = 0; for(int i=0;i<primeList.size();i++){ if(hashMap.get(primeList.get(i))>1) mult++; } if(primeList.size()==1){ System.out.println("Alice"); return; } if(primeList.size() % 2 == 0){ if(mult % 2 == 0){ System.out.println("Bob"); }else{ System.out.println("Alice"); } }else{ if(mult % 2 == 0){ System.out.println("Bob"); }else{ System.out.println("Alice"); } } } catch (IOException e) { e.printStackTrace(); } } }