結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
Naco
|
| 提出日時 | 2019-07-12 00:52:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 5,000 ms |
| コード長 | 1,452 bytes |
| コンパイル時間 | 577 ms |
| コンパイル使用メモリ | 75,792 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:22:17 |
| 合計ジャッジ時間 | 1,207 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
map<ll,ll> prime_factor(ll n){ //素因数分解
map<ll,ll> table;
for(int i=2;i*i<=n;i++){
while(n%i==0){
table[i]++;
n/=i;
}
}
if(n!=1) table[n]=1;
return table;// key->素因数, value->べき乗
}
bool is_prime(int n){ //素数判定
for(int i=2;i*i<=n;i++){
if(n%i==0) return true;
}
return false;
}
vector<bool> prime_table(int n){ //素数全列挙
vector<bool> prime(n+1,true);
prime[0]=prime[1]=false;
for(int i=2;i*i<=n;i++){
if(prime[i]!=true) continue;
for(int j=2*i;j<=n;j+=i){
prime[j]=false;
}
}
return prime; //i番目の要素が素数の場合trueを返す
}
vector<int> p;
int main(){
int N;
cin >> N;
vector<bool> p_table=prime_table(N);
for(int i=2;i<=N;i++){
if(p_table[i]==true){
p.push_back(i);
}
}
bool dp[N+1];
for(int i=0;i<=N;i++) dp[i]=false;
dp[0]=true;
dp[1]=true;
for(int i=2;i<=N;i++){
for(int j=0;j<p.size();j++){
if(dp[i]==true) continue; //勝つ選択肢が一つあればok
if(i-p[j]>=0){
if(!dp[i-p[j]]){
dp[i]=true;
}
}
}
}
if(dp[N]==true) cout << "Win" << endl;
else cout << "Lose" << endl;
}
Naco