結果

問題 No.12 限定された素数
ユーザー hogeover30hogeover30
提出日時 2015-02-17 15:44:22
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,135 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 51,512 KB
最終ジャッジ日時 2023-08-15 22:40:23
合計ジャッジ時間 728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:5: error: ‘vector’ was not declared in this scope
     vector<int> primes;
     ^~~~~~
main.cpp:8:5: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:8:5:
     vector<int> primes;
     ^~~~~~
main.cpp:8:12: error: expected primary-expression before ‘int’
     vector<int> primes;
            ^~~
main.cpp:9:12: error: expected primary-expression before ‘int’
     vector<int> v;
            ^~~
main.cpp:11:9: error: ‘primes’ was not declared in this scope
         primes.push_back(i);
         ^~~~~~
main.cpp:11:9: note: suggested alternative: ‘stime’
         primes.push_back(i);
         ^~~~~~
         stime
main.cpp:14:9: error: ‘v’ was not declared in this scope
         v.push_back(x);
         ^
main.cpp:22:25: error: ‘v’ was not declared in this scope
         int s=0, e=0, x=v[s];
                         ^
main.cpp:27:27: error: ‘primes’ was not declared in this scope
                     int L=primes[e]-1;
                           ^~~~~~
main.cpp:27:27: note: suggested alternative: ‘res’
                     int L=primes[e]-1;
                           ^~~~~~
                           res
main.cpp:40:25: error: ‘primes’ was not declared in this scope
                 int L=e<primes.size()?primes[e]-1:5000000;
                         ^~~~~~
main.cpp:40:25: note: suggested alternative: ‘res’
                 int L=e<primes.size()?primes[e]-1:5000000;
                         ^~~~~~
                         res

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
const int N=5000001;
int c[N];
int main()
{
    vector<int> primes;
    vector<int> v;
    for(int i=2;i<N;++i) if (!c[i]) {
        primes.push_back(i);
        int x=0;
        for(int t=i;t>0;t/=10) x|=1<<(t%10);
        v.push_back(x);
        for(int j=i+i;j<N;j+=i) c[j]=1;
    }

    int n;
    while (cin>>n) {
        int a=0;
        for(int i=0;i<n;++i) { int t; cin>>t; a|=1<<t; }
        int s=0, e=0, x=v[s];
        int res=-1;
        while (s<v.size() and e<v.size()) {
            if ((x|v[e]|a)>a) {
                if (x==a and s<e) {
                    int L=primes[e]-1;
                    int K=!!s*primes[s-1]+1;
                    res=max(res, L-K);
                }
                s=e+1;
                e=s;
                x=v[e];
            }
            else {
                x|=v[e];
                ++e;
            }
            if (x==a) {
                int L=e<primes.size()?primes[e]-1:5000000;
                int K=!!s*primes[s-1]+1;
                res=max(res, L-K);
            }
        }
        cout<<res<<endl;
    }
}
0