結果
| 問題 | No.12 限定された素数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-14 02:41:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 5,000 ms |
| コード長 | 592 bytes |
| 記録 | |
| コンパイル時間 | 494 ms |
| コンパイル使用メモリ | 64,384 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2024-11-24 10:15:46 |
| 合計ジャッジ時間 | 2,484 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main()
| ^~~~
ソースコード
#include<iostream>
using namespace std;
const int MAX=5000000;
bool isp[MAX+1];
int ok;
int f(int X)
{
int ret=0;
while(X)
{
ret|=1<<X%10;
X/=10;
}
return ret;
}
main()
{
int N;cin>>N;
for(int i=0;i<N;i++)
{
int a;cin>>a;ok|=1<<a;
}
int ans=-1,pre=1,now=0;
for(int i=2;i<=MAX;i++)isp[i]=true;
for(int i=2;i<=MAX;i++)
{
if(isp[i])
{
int x=f(i);
if(~ok&x)
{
if(now==ok)
{
ans=max(ans,i-1-pre);
}
now=0;
pre=i+1;
}
else now|=x;
for(int j=i+i;j<=MAX;j+=i)isp[j]=false;
}
}
if(now==ok)ans=max(ans,MAX-pre);
cout<<ans<<endl;
}