結果
問題 |
No.12 限定された素数
|
ユーザー |
![]() |
提出日時 | 2015-07-17 23:08:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 62 ms / 5,000 ms |
コード長 | 1,986 bytes |
コンパイル時間 | 994 ms |
コンパイル使用メモリ | 75,648 KB |
実行使用メモリ | 10,460 KB |
最終ジャッジ日時 | 2024-11-24 08:22:50 |
合計ジャッジ時間 | 3,522 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 43 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:59:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 59 | scanf("%d",&A); | ~~~~~^~~~~~~~~
ソースコード
#include <cstdio> #include <cstdlib> #include <iostream> #include <string> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <cstring> typedef long long ll; using namespace std; #define mod 1000000007 #define INF 1000000000 #define LLINF 2000000000000000000LL #define MAX_L 5000000 #define SIZE 1000000 vector<int> pnum; const int MAX_P = 5000000; bool prime[MAX_P+1]; void primen(void){ for(int i=2;i<=MAX_P;i++) prime[i]=true; for(int i=2;i*i<=MAX_P;i++) if(prime[i]) for(int j=i;i*j<=MAX_P;j++) prime[i*j]=false; } int main(){ int n,k,A,ans=-1,a,f; int m[10]={0},m_in[10]={0}; scanf("%d",&n); primen(); pnum.push_back(0); for(int i=2;i<=MAX_L;i++){ if(prime[i]==true){ pnum.push_back(i); } } pnum.push_back(5000001); for(int i=0;i<n;i++){ scanf("%d",&A); m_in[A]=1; } k=1; for(int l=1;l<pnum.size();l++){ while(1){ bool f = false; for(int i=0;i<10;i++){ if(m_in[i]==0 && m[i]>0) f = true; } if(f){ a = pnum[k]; while(a){ m[a%10]--; a/=10; } k++; }else{ break; } } bool f = true; for(int i=0;i<10;i++){ if(m_in[i]>0 && m[i]==0) f = false; } if(f){ ans = max(ans,(pnum[l]-1)-(pnum[k-1]+1)); } a = pnum[l]; while(a){ m[a%10]++; a/=10; } } printf("%d\n",ans); return 0; }