結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,260 ms
155,240 KB
testcase_01 AC 2,262 ms
155,448 KB
testcase_02 WA -
testcase_03 AC 2,230 ms
155,244 KB
testcase_04 AC 2,255 ms
155,472 KB
testcase_05 AC 2,257 ms
155,160 KB
testcase_06 AC 2,260 ms
155,308 KB
testcase_07 AC 2,254 ms
155,160 KB
testcase_08 AC 2,265 ms
155,208 KB
testcase_09 AC 2,266 ms
155,192 KB
testcase_10 AC 2,258 ms
155,348 KB
testcase_11 AC 2,271 ms
155,176 KB
testcase_12 AC 2,256 ms
155,264 KB
testcase_13 AC 2,256 ms
155,208 KB
testcase_14 AC 2,256 ms
155,184 KB
testcase_15 AC 2,259 ms
155,196 KB
testcase_16 AC 2,260 ms
155,208 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2,254 ms
155,264 KB
testcase_21 AC 2,263 ms
155,244 KB
testcase_22 AC 2,260 ms
155,192 KB
testcase_23 AC 2,259 ms
155,212 KB
testcase_24 AC 2,275 ms
155,156 KB
testcase_25 AC 2,264 ms
155,176 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(~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