結果
問題 |
No.7 プライムナンバーゲーム
|
ユーザー |
![]() |
提出日時 | 2018-01-29 23:40:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 1,122 bytes |
コンパイル時間 | 1,125 ms |
コンパイル使用メモリ | 157,996 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 16:08:39 |
合計ジャッジ時間 | 1,802 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> #include "bits/stdc++.h" #include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <string> #include <sstream> #include <cmath> #include <stack> #include <queue> #include <cctype> #include <stdio.h> #include <map> #include <string.h> #include <utility> typedef long long ll; #define INF (1e9+1) #define rep(i,n) for(ll i=0;i<(ll)(n);i++) using namespace std; typedef pair<int, int> P; bool prime[100001]; void shieve(int n){ for(int i=0; i<=n; i++){ prime[i] = true;; } for(int i=2; i<=n; i++){ if(prime[i]){ for(int j= 2*i; j<=n; j +=i){ prime[j] =false; } } } } bool game[100001]; int main(){ int n; cin>>n; shieve(n); game[0] =true; game[1] = true; for(int i=2; i<=n; i++){ for(int j=i; j>=2; j--){ if(prime[j]){ if(n-j<0){ break; } game[i] = !game[i-j]; if(game[i])break; /*cout<<i<<!game[n-j]<<endl;*/ } } } /* rep(i,16){ if(game[i]){ cout<<"win"<<i<<endl; }else { cout<<"lose"<<i<<endl; } }*/ if(game[n]){ cout<<"Win"<<endl; }else { cout<<"Lose"<<endl; } }