結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー hogeover30hogeover30
提出日時 2016-05-19 01:36:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 665 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 62,016 KB
最終ジャッジ日時 2024-04-27 02:20:48
合計ジャッジ時間 757 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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) {
      |               ^~~~~~

ソースコード

diff #

#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;
            }
        }
    }
}
0