結果

問題 No.7 プライムナンバーゲーム
ユーザー niyarinniyarin
提出日時 2017-03-28 00:59:30
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 969 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 32,868 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:12:25
合計ジャッジ時間 1,199 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<math.h>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,(n))

int N;
int prime[10001]={0};
int pcnt=0;
int dp[10001] = {0};

void sieve(){
    int sie[10001];
    REP(i,N+1){
        sie[i] = 1;
    }
    sie[0] = 0;
    sie[1] = 0;
    FOR(i,1,N+1){
        if (sie[i]){
            for (int j=2*i;j<=N;j+=i){
                sie[j] = 0;
            }
        }
    }
    
    pcnt = 0;
    REP(i,N+1){
        if (sie[i]){
            prime[pcnt] = i;
            pcnt++;
        }
    }
}



void solve(){
    sieve();
    dp[0] = 1;
    dp[1] = 1;
    FOR(i,2,N+1){
        REP(j,pcnt){
            if (prime[j]<=i){
                if (!(dp[i-prime[j]])){
                    dp[i] = 1;
                    break;
                }
            }
        }
    }
    if (dp[N]){
        printf("Win\n");
    }else{
        printf("Lose\n");
    }
}


int main(void){
    scanf("%d",&N);
    solve();
    return 0;
}
0