結果

問題 No.6 使いものにならないハッシュ
ユーザー pekempeypekempey
提出日時 2015-08-18 14:47:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,133 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 154,904 KB
実行使用メモリ 5,012 KB
最終ジャッジ日時 2023-09-25 12:47:48
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,756 KB
testcase_01 AC 8 ms
4,936 KB
testcase_02 AC 9 ms
4,896 KB
testcase_03 AC 8 ms
4,912 KB
testcase_04 AC 8 ms
4,752 KB
testcase_05 AC 8 ms
4,860 KB
testcase_06 AC 8 ms
4,888 KB
testcase_07 AC 8 ms
4,892 KB
testcase_08 AC 9 ms
4,824 KB
testcase_09 AC 8 ms
4,916 KB
testcase_10 AC 7 ms
4,708 KB
testcase_11 WA -
testcase_12 AC 9 ms
4,828 KB
testcase_13 AC 8 ms
4,972 KB
testcase_14 AC 9 ms
4,712 KB
testcase_15 WA -
testcase_16 AC 8 ms
4,940 KB
testcase_17 AC 9 ms
4,876 KB
testcase_18 WA -
testcase_19 AC 9 ms
4,940 KB
testcase_20 AC 9 ms
4,940 KB
testcase_21 AC 8 ms
4,704 KB
testcase_22 AC 9 ms
4,924 KB
testcase_23 AC 9 ms
4,716 KB
testcase_24 AC 9 ms
4,712 KB
testcase_25 AC 9 ms
4,860 KB
testcase_26 AC 9 ms
4,936 KB
testcase_27 AC 9 ms
4,752 KB
testcase_28 WA -
testcase_29 AC 9 ms
4,772 KB
testcase_30 AC 9 ms
4,924 KB
testcase_31 AC 9 ms
4,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int K, N;

const int maxn = 1e6;
bool isprime[maxn];
vector<int> prime;
vector<int> h;

int f(int n) {
	return 1 + (n - 1) % 9;
}

void sieve() {
	fill(isprime, isprime + maxn, true);
	for (ll i = 2; i < maxn; i++) {
		if (isprime[i]) {
			prime.push_back(i);
			h.push_back(f(i));
			for (ll j = i * i; j < maxn; j += i) {
				isprime[j] = false;
			}
		}
	}
}

int main() {
	sieve();
	int K, N;
	cin >> K >> N;
	K = lower_bound(prime.begin(), prime.end(), K) - prime.begin();
	N = upper_bound(prime.begin(), prime.end(), N) - prime.begin();

	int r = K;
	set<int> s;
	pair<int, int> ans(-1, 0);
	rep2 (i, K, N + 1) {
		while (r <= N && !s.count(h[r])) {
			s.insert(h[r]);
			r++;
		}
		ans = max(ans, make_pair((int)s.size(), prime[i]));
		s.erase(h[i]);
	}

	cout << ans.second << endl;

	return 0;
}
0