結果

問題 No.2 素因数ゲーム
ユーザー ぴろずぴろず
提出日時 2014-12-21 11:52:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 1,718 bytes
コンパイル時間 2,724 ms
コンパイル使用メモリ 85,616 KB
実行使用メモリ 56,140 KB
最終ジャッジ日時 2023-08-27 03:37:55
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,728 KB
testcase_01 AC 125 ms
55,728 KB
testcase_02 AC 127 ms
55,456 KB
testcase_03 AC 127 ms
56,140 KB
testcase_04 AC 127 ms
55,876 KB
testcase_05 AC 133 ms
55,664 KB
testcase_06 AC 128 ms
55,740 KB
testcase_07 AC 127 ms
55,444 KB
testcase_08 AC 131 ms
55,848 KB
testcase_09 AC 129 ms
55,924 KB
testcase_10 AC 129 ms
56,008 KB
testcase_11 AC 131 ms
55,456 KB
testcase_12 AC 130 ms
55,756 KB
testcase_13 AC 130 ms
55,668 KB
testcase_14 AC 130 ms
55,508 KB
testcase_15 AC 125 ms
55,756 KB
testcase_16 AC 129 ms
55,924 KB
testcase_17 AC 129 ms
55,620 KB
testcase_18 AC 138 ms
55,432 KB
testcase_19 AC 133 ms
55,616 KB
testcase_20 AC 131 ms
55,860 KB
testcase_21 AC 130 ms
55,852 KB
testcase_22 AC 129 ms
55,804 KB
testcase_23 AC 127 ms
55,596 KB
testcase_24 AC 127 ms
55,464 KB
testcase_25 AC 129 ms
55,832 KB
testcase_26 AC 127 ms
55,676 KB
testcase_27 AC 127 ms
55,444 KB
testcase_28 AC 129 ms
55,676 KB
testcase_29 AC 130 ms
55,968 KB
testcase_30 AC 131 ms
55,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no002;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Sieve.Factor> factor = Sieve.primeFactor(n);
		int ans = 0;
		for(Sieve.Factor f: factor) {
			ans ^= f.exp;
		}
		if (ans == 0) {
			System.out.println("Bob");
		}else{
			System.out.println("Alice");
		}
	}

}
class Sieve {
	public static boolean[] isPrimeArray(int max) {
		boolean[] isPrime = new boolean[max+1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i=2;i*i<=max;i++) {
			if (isPrime[i]) {
				int j = i * 2;
				while(j<=max) {
					isPrime[j] = false;
					j += i;
				}
			}
		}
		return isPrime;
	}
	public static ArrayList<Integer> primeList(int max) {
		boolean[] isPrime = isPrimeArray(max);
		ArrayList<Integer> primeList = new ArrayList<>();
		for(int i=2;i<=max;i++) {
			if (isPrime[i]) {
				primeList.add(i);
			}
		}
		return primeList;
	}
	public static ArrayList<Factor> primeFactor(ArrayList<Integer> primeList,long num) {
		ArrayList<Factor> ret = new ArrayList<Factor>();
		for(int p:primeList) {
			int exp = 0;
			while(num % p == 0) {
				num /= p;
				exp++;
			}
			if (exp > 0) {
				ret.add(new Factor(p,exp));
			}
		}
		if (num >= 2) {
			ret.add(new Factor((int) num,1));
		}
		return ret;
	}
	public static ArrayList<Factor> primeFactor(long num) {
		return primeFactor(primeList((int) (Math.sqrt(num) + 0.5)), num);
	}
	public static class Factor {
		int base,exp;
		public Factor(int base,int exp) {
			this.base = base;
			this.exp = exp;
		}
		public String toString() {
			return base + "^" + exp;
		}
	}
}
0