結果
| 問題 | No.458 異なる素数の和 |
| コンテスト | |
| ユーザー |
DA__1337
|
| 提出日時 | 2019-08-10 16:45:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 958 bytes |
| 記録 | |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 170,508 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 17:12:20 |
| 合計ジャッジ時間 | 8,094 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 28 |
コンパイルメッセージ
main.cpp: In function 'bool sieve(ll)':
main.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
23 | }
| ^
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll maxNum=20001;
vector<bool> isPrime(maxNum,true);
bool sieve(ll n){
isPrime[0]=false;
isPrime[1]=false;
for(ll i=2;i<n;i++){
if(!isPrime[i]) continue;
for(int j=i*2;j<=n;j+=i) isPrime[j]=false;
}
}
int main(){
int n;
cin>>n;
sieve(20001);
vector<ll> prime_list;
rep(i,20001){
if(isPrime[i]) prime_list.push_back(i);
}
vector<ll> dp(100000,-1);
dp[0]=0;
for(auto p : prime_list){
for(int i=20000;i>=0;i--){
if(dp[i]<0) continue;
if(dp[i+p]<dp[i]+1)
dp[i+p]=dp[i]+1;
}
}
cout<<dp[n]<<endl;
return 0;
}
DA__1337