結果

問題 No.7 プライムナンバーゲーム
ユーザー Shirapon_ponShirapon_pon
提出日時 2021-05-15 01:07:05
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2,095 ms / 5,000 ms
コード長 936 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 30,592 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:04:04
合計ジャッジ時間 4,810 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 4 ms
6,948 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 51 ms
6,948 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2,095 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 119 ms
6,944 KB
testcase_15 AC 112 ms
6,944 KB
testcase_16 AC 1,448 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int is_prime_num(int num);
int game(int num, int turn);

int main(int argc, char *argv[]){
    int n;
    scanf("%d",&n);
    if (game(n,1) == 1)
    {
        printf("Win\n");
    } else
    {
        printf("Lose\n");
    }
    return 0;
}

int is_prime_num(int num)
{
    int flag = 1;
    for (int i = 2; i < num; i++)
    {
        if (num % i == 0)
        {
            flag = 0;
            break;
        }
    }
    return flag;
}

int game(int num, int turn)
{
    int win = 0;
    if (num == 0 || num == 1)
    {
        win = turn;
    } else
    {
        for (int i = num; i >= 2; i--)
        {
            if (is_prime_num(i))
            {
                if (game(num-i,3-turn) == turn)
                {
                    win = turn;
                    break;
                }
            }
        }
        if (win == 0)
        {
            win = 3-turn;
        }
    }
    return win;
}
0