結果
| 問題 |
No.458 異なる素数の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-15 00:05:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 737 bytes |
| コンパイル時間 | 2,607 ms |
| コンパイル使用メモリ | 197,384 KB |
| 最終ジャッジ日時 | 2025-01-10 10:58:05 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | int n; scanf("%d",&n);
| ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
class Eratosthenes_sieve{
vector<bool> er;
vector<int> p;
public:
Eratosthenes_sieve(int n):er(n+1,true){
if(n>=0) er[0]=false;
if(n>=1) er[1]=false;
for(int i=2;i*i<=n;i++) if(er[i]) for(int j=i*i;j<=n;j+=i) er[j]=false;
rep(i,n+1) if(er[i]) p.emplace_back(i);
}
vector<int> primes()const{ return p; }
bool is_prime(int a)const{
assert(a<=(int)er.size()-1);
return a>=0 && er[a];
}
};
int main(){
int n; scanf("%d",&n);
vector<int> dp(n+1,-INF);
dp[0]=0;
for(int p:Eratosthenes_sieve(n).primes()){
for(int a=n;a>=p;a--) dp[a]=max(dp[a],dp[a-p]+1);
}
printf("%d\n",max(dp[n],-1));
return 0;
}