結果

問題 No.2 素因数ゲーム
ユーザー 4885rhkA
提出日時 2015-07-16 08:28:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,348 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 59,612 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 11:35:49
合計ジャッジ時間 1,930 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

//
//  main.cpp
//  Q18
//
//  Created by AkihiroKOBAYASHI on 7/15/15.
//  Copyright (c) 2015 Akhr5884. All rights reserved.
//

#include <iostream>
#include <math.h>

int main(int argc, const char * argv[]) {
    
    int a, n, i, j;
    int count[10000] = {0};
    int countnumber[10000] = {0};
    int nim = 0;
    std::cin >> n;
    
    a = (int)(sqrt(n)) + 1;
    
    for(i = 2; i <= a; i++) {
        count[i] = 1;
    }
    
    // sosu
    for(i = 2; i <= a; i++) {
        if(count[i] == 1) {
            for(j = i; j * i <= a; j++) {
                count[i*j] = 0;
            }
        }
    }

    // wareru
    for(i = 2; i <= a; i++) {
        if(count[i] == 1 && n % i != 0) {
            count[i] = 0;
        }
    }
    
    j = n;
    for(i = 2; i <=a; i++) {
        if(count[i] == 1 && j%i == 0) {
            while(j%i == 0) {
                countnumber[i]++;
                j = j/i;
            }
//            std::cout << i << " " << countnumber[i] << "\n";
            nim = nim ^ countnumber[i];
        }
    }
    
    if(j != 1) {
        count[j] = 1;
        countnumber[j] = 1;
//        std::cout << j << " " << countnumber[j] << "\n";
        nim = nim ^ countnumber[j];
    }
    
    if(nim != 0) {
        std::cout << "Alice\n";
    }
    else {
        std::cout << "Bob\n";
    }

    
    return 0;
}
0