結果
| 問題 |
No.458 異なる素数の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-09 01:02:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 876 bytes |
| コンパイル時間 | 801 ms |
| コンパイル使用メモリ | 82,852 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-28 15:38:46 |
| 合計ジャッジ時間 | 1,736 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 6 |
ソースコード
#include "iostream"
#include "time.h"
#include "stdlib.h"
#include "iomanip"
#include "math.h"
#include "algorithm"
#include "functional"
#include "list"
using namespace std;
int n;
list<int>p;
bool flag;
int ans;
int sum;
int main() {
cin >> n;
p.push_back(2);
for (int i = 3; i <= n; i++) {
flag = true;
for (auto j = p.begin(); (*j)*(*j) <= i; ++j) {
if (i % (*j)==0) {
flag = false;
break;
}
}
if (flag)p.push_back(i);
}
for (auto i = p.begin(); sum<n; ++i) {
//cout << (*i) << "\n";
sum += (*i);
ans++;
}
//cout << sum << "\n";
for (auto i = p.begin(); (*i) <= sum - n; ++i) {
if ((*i) == sum - n) {
cout << ans - 1 << "\n";
return 0;
}
}
if (sum - n > 0) {
if ((sum - n) % 2 == 0)ans -= 2;
else ans -= 3;
}
if (n == 6)ans = -1;
if (ans <= 0) {
cout << "-1\n";
return 0;
}
cout << ans << "\n";
return 0;
}