結果
問題 |
No.2 素因数ゲーム
|
ユーザー |
![]() |
提出日時 | 2017-09-12 22:12:22 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,664 bytes |
コンパイル時間 | 3,845 ms |
コンパイル使用メモリ | 77,312 KB |
実行使用メモリ | 126,180 KB |
最終ジャッジ日時 | 2024-11-07 17:27:04 |
合計ジャッジ時間 | 12,072 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 TLE * 1 -- * 22 |
ソースコード
package yukicoder; import java.util.Scanner; public class PrimeFactorsGame { public static void main(String[] args) { @SuppressWarnings("resource") Scanner s = new Scanner(System.in); int num = s.nextInt(); int pfac[] = new int[10000000]; int pfac2[] = new int[10000000]; if(jud(num)){ System.out.println("Alice"); }else{ int cnt = 0; int cnt2 = 0; pfac[cnt++] = 2; pfac2[cnt2] = 0; boolean flg = (num % 2) == 0; if(flg){ while((num % 2) == 0){ pfac2[cnt2]++; num /= 2; } cnt2++; } for(int i = 3 ; i <= num ; i += 2){ flg = true; for(int j = 0 ; j < cnt ; j++){ if(i % pfac[j] == 0){ flg = false; break; } } if(flg){ pfac[cnt++] = i; if((num % i) == 0){ pfac2[cnt] = 0; while((num % i) == 0){ pfac2[cnt2]++; num /= i; } cnt2++; } } } flg = false; a: for(int i = 0 ; i < cnt2 ; i++){ for(int get = pfac2[i] - 1; get >= 0 ; get--){ int pf = 0; for(int j = 0 ; j < cnt2 ; j++){ if(i == j){ pf ^= get; }else{ pf ^= pfac2[j]; } } if(pf == 0){ flg = true; break a; } } } if(flg){ System.out.println("Alice"); }else{ System.out.println("Bob"); } } } private static boolean jud(int num) { if(num == 2){ return true; } if(num % 2 == 0){ return false; } double sqr = Math.sqrt(num); for(int i = 3 ; i <= sqr ; i += 2){ if(num % i == 0){ return false; } } return true; } }