結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2018-06-03 10:55:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 628 ms / 5,000 ms |
コード長 | 1,667 bytes |
コンパイル時間 | 1,028 ms |
コンパイル使用メモリ | 107,200 KB |
最終ジャッジ日時 | 2025-01-05 10:48:28 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <map> #include <cmath> #include <string> int main() { int n = 0; std::cin >> n; //邏�謨ー繧呈アゅa繧� std::vector<int> primes; std::vector<int> tmp; for(int i = 2; i <= n; ++i ) { tmp.push_back(i); } while( 1 ) { if(tmp.size()==0) break; int i = tmp[0]; primes.push_back(i); if(std::sqrt(n) <= i) break; std::vector<int> t; for(auto x: tmp){ if(x%i != 0){ t.push_back(x); } } tmp = t; } for(auto x: tmp){ primes.push_back(x); } //蜍昴■雋�縺僧ap繧剃ス懊k std::map<int, bool> winlose; winlose[0] = false; winlose[1] = false; for( int i = 2; i <= n; ++i ){ winlose[i] = false; for( auto const prime: primes) { if(prime > i ){ break; } if(i-prime >= 2&& winlose[i-prime]==false){ // std::cout << "win[ " << i << " ] root: " << prime << std::endl; // std::cout << "[i-prime]: " << winlose[i-prime] << std::endl; winlose[i] = true; } } } //for(auto i: primes) // std::cout << i << std::endl; for(auto i: winlose){ //std::cout << "winlose[ " << i.first << " ]: " << i.second << std::endl; } std::string wl = "Win"; if(winlose[n]==false) wl = "Lose"; std::cout << wl << std::endl; return 0; }