結果

問題 No.7 プライムナンバーゲーム
ユーザー akakimidoriakakimidori
提出日時 2016-02-19 14:39:20
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 670 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:55:29
合計ジャッジ時間 1,152 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,820 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 37 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 0 ms
6,944 KB
testcase_06 AC 9 ms
6,944 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 15 ms
6,944 KB
testcase_10 AC 0 ms
6,948 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 25 ms
6,948 KB
testcase_13 AC 28 ms
6,944 KB
testcase_14 AC 37 ms
6,948 KB
testcase_15 AC 35 ms
6,948 KB
testcase_16 AC 32 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:9:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

#define M 10000

void run(void){

  int n;
  scanf("%d",&n);

  char *isPrime;
  isPrime=(char *)malloc(sizeof(char)*(M+1));
  int i,j;
  isPrime[0]=isPrime[1]=0;
  for(i=2;i<=M;i++) isPrime[i]=1;
  for(i=2;i*i<=M;i++){
    if(isPrime[i]){
      for(j=i*i;j<=M;j+=i){
        isPrime[j]=0;
      }
    }
  }

  char *win;
  win=(char *)calloc(M+1,sizeof(char));
  win[0]=win[1]=1;
  for(i=2;i<=n;i++){
    for(j=2;j<=i;j++){
      if(isPrime[j] && !win[i-j]){
        win[i]=1;
        break;
      }
    }
  }
  printf("%s\n",win[n]?"Win":"Lose");

  free(isPrime);
  free(win);
  return;
}

int main(void){
  run();
  return 0;
}
0