結果

問題 No.2 素因数ゲーム
ユーザー @abcde@abcde
提出日時 2019-06-05 01:17:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,942 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 175,912 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 02:34:16
合計ジャッジ時間 3,478 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long;

// Efficient program to print all prime factors of a given number
// https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/
// 与えられた正整数についての素因数分解を計算.
// @param X: 素因数分解を行う整数.
// @return ret: 素因数分解 の 結果 を 返却.
map<LL, int> getAllDivisors(LL X) {
    
    // 1. X を 2で割り切れなくなるまで割っていく.
    map<LL, int> ret;
    while(X % 2 == 0) ret[2]++, X >>= 1;
    
    // 2. X を 3以上の奇数で, 割り切れなくなるまで順次割っていく.
    for(LL i = 3; i <= sqrt(X); i += 2){
        while(X % i == 0){
            ret[i]++;
            X /= i;
        }
    }
    
    // 3. X が 2 より 大きな素数であれば, 追加.
    if(X > 2) ret[X]++;
    
    // 4. 出力.
    return ret;
}

int main() {
    
    // 1. 入力情報取得.
    LL N;
    scanf("%llu", &N);

    // 2. 与えられた正の整数について, 素因数分解を行う.
    map<LL, int> divisors = getAllDivisors(N);
    // ex.
    // N = 1020304030201
    // 73 2
    // 101 2
    // 137 2
    // for(auto &p : divisors) cout << p.first << " " << p.second << endl;
    
    // 3. 素因数が, 1個, 2個以上 の ものを カウント.
    int one = 0, two = 0;
    for(auto &p : divisors){
        if(p.second == 1) one++;
        if(p.second > 1)  two++;
    }
    
    // 4. Alice, Bob の 勝者 を 検討.
    bool alice = false;
    // 4-1. two が 0個 の 場合.
    if(two == 0){
        if(one % 2 == 0) alice = false;
        else             alice = true;
    }
    
    // 4-2. two が 1個以上 の 場合.
    if(two > 0){
        if(two % 2 == 0) alice = false;
        else             alice = true;
    }
    
    // 4. 出力.
    if(alice) printf("%s\n", "Alice");
    else      printf("%s\n", "Bob");
    return 0;
    
}
0