結果

問題 No.12 限定された素数
ユーザー cureskolcureskol
提出日時 2020-03-27 11:07:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 170,992 KB
実行使用メモリ 155,472 KB
最終ジャッジ日時 2023-08-30 16:21:22
合計ジャッジ時間 66,031 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,266 ms
155,168 KB
testcase_01 AC 2,260 ms
155,232 KB
testcase_02 WA -
testcase_03 AC 2,223 ms
155,216 KB
testcase_04 AC 2,257 ms
155,160 KB
testcase_05 AC 2,260 ms
155,288 KB
testcase_06 AC 2,256 ms
155,468 KB
testcase_07 AC 2,266 ms
155,224 KB
testcase_08 AC 2,261 ms
155,224 KB
testcase_09 AC 2,265 ms
155,220 KB
testcase_10 AC 2,256 ms
155,156 KB
testcase_11 AC 2,265 ms
155,472 KB
testcase_12 AC 2,262 ms
155,232 KB
testcase_13 AC 2,261 ms
155,216 KB
testcase_14 AC 2,255 ms
155,156 KB
testcase_15 AC 2,262 ms
155,156 KB
testcase_16 AC 2,261 ms
155,160 KB
testcase_17 WA -
testcase_18 AC 2,257 ms
155,216 KB
testcase_19 AC 2,256 ms
155,344 KB
testcase_20 AC 2,258 ms
155,148 KB
testcase_21 AC 2,256 ms
155,460 KB
testcase_22 AC 2,256 ms
155,184 KB
testcase_23 AC 2,261 ms
155,180 KB
testcase_24 AC 2,257 ms
155,228 KB
testcase_25 AC 2,315 ms
155,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
vector<int> F[5000001];
int P[5000001];

bool prime(int a){
  if(a==1)return 0;
  if(~P[a])return P[a];
  for(int i=2;i*i<=a;i++)if(a%i==0)return P[a]=0;
  return P[a]=1;
}
vector<int> f(int a){
  if(F[a].size())return F[a];
  int tmp=a;
  vector<int> res;
  while(a){
    res.push_back(a%10);
    a/=10;
  }
  return F[tmp]=res;
}


signed main(){
  memset(P,-1,sizeof(P));
  int n;cin>>n;
  int ans=0;
  vector<int> v(10,0),now(10,0);
  while(n--){int a;cin>>a;v[a]++;}
  for(int l=1,r=1;r<=5000000;r++){
    if(prime(r)){
      for(int p:f(r))now[p]++;
      while(true){
        bool fl=false;
        for(int i=0;i<10;i++)if((!v[i])&&now[i])fl=1;
        if(fl){
          while(!prime(l))l++;
          for(int p:f(l))now[p]--;
          l++;
        }
        else break;
      }
    }
    int a=0;
    for(int i=0;i<10;i++)if((v[i]&&!now[i])||(!v[i]&&now[i]))a=1;
    if(!a)chmax(ans,r-l);
  }
  cout<<ans<<endl;
}
0