結果
問題 |
No.12 限定された素数
|
ユーザー |
![]() |
提出日時 | 2015-04-24 00:22:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 41 ms / 5,000 ms |
コード長 | 785 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 42,752 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 08:18:08 |
合計ジャッジ時間 | 2,325 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’: main.cpp:5:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 5 | inline int getInt(){ int s; scanf("%d", &s); return s; } | ~~~~~^~~~~~~~~~
ソースコード
#include <queue> #define REP(i,n) for(int i=0; i<(int)(n); i++) #include <cstdio> inline int getInt(){ int s; scanf("%d", &s); return s; } #include <set> using namespace std; int f(int a){ int ret = 0; while(a){ ret |= 1 << (a % 10); a /= 10; } return ret; } int main(){ const int n = getInt(); int a = 0; REP(i,n) a |= 1 << getInt(); vector<bool> isPrime(5000000 + 1, true); int low = 1; int cur = 0; int ans = -1; for(int i = 2; i <= 5000000; i++){ if(isPrime[i]){ cur |= f(i); if(cur & ~a){ cur = 0; low = i + 1; } for(int j = i + i; j <= 5000000; j += i){ isPrime[j] = false; } } if(cur == a){ ans = max(ans, i - low); } } printf("%d\n", ans); return 0; }