結果

問題 No.2 素因数ゲーム
ユーザー Amanita2016Amanita2016
提出日時 2017-09-12 22:12:22
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,664 bytes
コンパイル時間 3,606 ms
コンパイル使用メモリ 78,116 KB
実行使用メモリ 121,480 KB
最終ジャッジ日時 2024-04-25 07:11:33
合計ジャッジ時間 11,991 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
120,920 KB
testcase_01 AC 169 ms
120,104 KB
testcase_02 AC 181 ms
121,480 KB
testcase_03 AC 173 ms
121,216 KB
testcase_04 AC 180 ms
121,036 KB
testcase_05 AC 176 ms
120,960 KB
testcase_06 AC 184 ms
120,092 KB
testcase_07 AC 169 ms
120,316 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	}

}
0