結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-19 15:34:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 723 bytes |
| コンパイル時間 | 321 ms |
| コンパイル使用メモリ | 51,740 KB |
| 最終ジャッジ日時 | 2024-11-14 20:05:13 |
| 合計ジャッジ時間 | 740 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:3: error: ‘vector’ was not declared in this scope
7 | vector<bool> is_prime(N+1, true);
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:7:10: error: expected primary-expression before ‘bool’
7 | vector<bool> is_prime(N+1, true);
| ^~~~
main.cpp:8:3: error: ‘is_prime’ was not declared in this scope
8 | is_prime[0] = false;
| ^~~~~~~~
main.cpp:17:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:20:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | int x; scanf("%d", &x);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
constexpr int N = int(5e6);
vector<bool> is_prime(N+1, true);
is_prime[0] = false;
is_prime[1] = false;
for(int i=2; i*i<=N; ++i) {
if(is_prime[i]) {
for(int j=i*i; j<=N; j+=i) {
is_prime[j] = false;
}
}
}
int n; scanf("%d", &n);
int S = 0;
for(int i=0; i<n; ++i) {
int x; scanf("%d", &x);
S |= 1<<x;
}
int maxi = -1;
int T = 0;
for(int k=1, l=1; l<=N; ++l) {
if(is_prime[l]) {
for(int j=l; j; j/=10) { T |= 1<<j%10; }
}
if(S == T) {
maxi = max(maxi, l-k);
} else if(~S & T) {
T = 0;
k = l+1;
}
}
printf("%d\n", maxi);
return 0;
}