結果

問題 No.103 素因数ゲーム リターンズ
ユーザー kou6839kou6839
提出日時 2015-03-28 00:55:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 76,760 KB
実行使用メモリ 61,764 KB
最終ジャッジ日時 2023-09-11 10:45:35
合計ジャッジ時間 7,651 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
61,376 KB
testcase_01 AC 166 ms
61,008 KB
testcase_02 AC 163 ms
60,704 KB
testcase_03 AC 167 ms
61,196 KB
testcase_04 AC 164 ms
60,736 KB
testcase_05 AC 165 ms
61,440 KB
testcase_06 AC 165 ms
61,228 KB
testcase_07 AC 168 ms
61,200 KB
testcase_08 AC 168 ms
61,396 KB
testcase_09 AC 165 ms
60,612 KB
testcase_10 AC 168 ms
60,896 KB
testcase_11 AC 166 ms
60,596 KB
testcase_12 AC 173 ms
61,188 KB
testcase_13 AC 174 ms
61,504 KB
testcase_14 AC 176 ms
61,492 KB
testcase_15 AC 177 ms
61,192 KB
testcase_16 AC 166 ms
60,984 KB
testcase_17 AC 174 ms
61,484 KB
testcase_18 AC 176 ms
61,764 KB
testcase_19 AC 180 ms
61,568 KB
testcase_20 AC 172 ms
61,636 KB
testcase_21 AC 173 ms
61,740 KB
testcase_22 AC 172 ms
60,432 KB
testcase_23 AC 175 ms
61,204 KB
testcase_24 AC 180 ms
61,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.*;
public class Main {
	static int[] grandy;
	static int cul(int x){
		int www=x;
		if(grandy[x]!=-1) return grandy[x];
		Set<Integer> set = new HashSet<>();
		for(int i=2;i*i<=x;i++){
			if(x%i==0){
				x/=i;
				set.add(cul(www/i));
				if(x%i==0){
					set.add(cul(www/(i*i)));
					while(x%i==0) x/=i;
				}
			}
		}
		if(x>1){
			set.add(cul(www/x));
		}
		int res=0;
		while(set.contains(res)) res++;
		return grandy[www]=res;
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		grandy = new int[10001];
		Arrays.fill(grandy, -1);
		grandy[0]=0;
		grandy[1]=0;
		for(int i=2;i<10001;i++){
			grandy[i]=cul(i);
		}
		int n = sc.nextInt();
		int ans=0;
		for(int i=0;i<n;i++){
			ans^=grandy[sc.nextInt()];
		}
		if(ans==0){
			System.out.println("Bob");
		}else{
			System.out.println("Alice");
		}
	}
}
0