結果

問題 No.2 素因数ゲーム
ユーザー Amanita2016
提出日時 2017-09-14 08:52:10
言語 Java
(openjdk 23)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 6,289 ms
コンパイル使用メモリ 74,072 KB
実行使用メモリ 36,932 KB
最終ジャッジ日時 2024-12-26 13:14:35
合計ジャッジ時間 7,571 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PrimeFactorsGame {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int num = 0;
		try {
			num = Integer.parseInt(br.readLine());
		}catch (IOException e){}
		double sqr = Math.sqrt(num);
		int xor = 0;
		int cnt = 0;
		while((num & 1) == 0){
			cnt++;
			num /= 2;
		}
		xor ^= cnt;
		for(int i = 3 ; i <= sqr ; i += 2){
			if((num % i) == 0){
				cnt = 0;
				do{
					num /= i;
					cnt++;
				}while((num % i) == 0);
				xor ^= cnt;
			}
		}
		if(num != 1){
			xor ^= 1;
		}
		String disp = (xor == 0) ? "Bob" : "Alice";
		System.out.println(disp);
	}
}
0