結果
| 問題 |
No.371 ぼく悪いプライムじゃないよ
|
| コンテスト | |
| ユーザー |
hogeover30
|
| 提出日時 | 2016-05-19 01:36:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 665 bytes |
| コンパイル時間 | 944 ms |
| コンパイル使用メモリ | 62,772 KB |
| 最終ジャッジ日時 | 2024-11-14 19:44:13 |
| 合計ジャッジ時間 | 1,671 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:10:5: error: 'vector' was not declared in this scope
10 | vector<bool> c(n+1);
| ^~~~~~
main.cpp:4:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
3 | #include <cmath>
+++ |+#include <vector>
4 | using namespace std;
main.cpp:10:12: error: expected primary-expression before 'bool'
10 | vector<bool> c(n+1);
| ^~~~
main.cpp:12:12: error: expected primary-expression before 'long'
12 | vector<long> primes;
| ^~~~
main.cpp:13:35: error: 'c' was not declared in this scope
13 | for(long i=2; i<=n; ++i) if (!c[i]) {
| ^
main.cpp:15:9: error: 'primes' was not declared in this scope
15 | primes.push_back(i);
| ^~~~~~
main.cpp:18:15: error: 'primes' was not declared in this scope
18 | for(int i=primes.size()-1; i>=0; --i) {
| ^~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
long L, H; cin>>L>>H;
const int n=sqrt(H);
vector<bool> c(n+1);
vector<long> primes;
for(long i=2; i<=n; ++i) if (!c[i]) {
for(long j=i*i; j<=n; j+=i) c[j]=1;
primes.push_back(i);
}
for(int i=primes.size()-1; i>=0; --i) {
auto p=primes[i];
for(auto t=H/p*p; t>=L; t-=p) {
if (t<p*p) break;
bool ok=true;
for(int j=0; ok&&(j<i); ++j) if (t%primes[j]==0) ok=false;
if (ok) {
cout<<t<<endl;
return 0;
}
}
}
}
hogeover30