結果

問題 No.6 使いものにならないハッシュ
ユーザー pekempeypekempey
提出日時 2015-08-18 14:49:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,128 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 154,992 KB
実行使用メモリ 5,044 KB
最終ジャッジ日時 2023-10-14 22:54:46
合計ジャッジ時間 2,910 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,732 KB
testcase_01 AC 8 ms
4,732 KB
testcase_02 AC 10 ms
4,892 KB
testcase_03 AC 8 ms
4,932 KB
testcase_04 AC 8 ms
4,728 KB
testcase_05 AC 8 ms
4,764 KB
testcase_06 AC 9 ms
4,768 KB
testcase_07 AC 9 ms
5,004 KB
testcase_08 AC 9 ms
4,720 KB
testcase_09 AC 9 ms
4,768 KB
testcase_10 AC 8 ms
4,828 KB
testcase_11 AC 8 ms
4,868 KB
testcase_12 AC 9 ms
4,720 KB
testcase_13 AC 8 ms
4,712 KB
testcase_14 AC 9 ms
4,984 KB
testcase_15 AC 9 ms
4,932 KB
testcase_16 AC 8 ms
4,712 KB
testcase_17 AC 9 ms
4,932 KB
testcase_18 AC 10 ms
4,708 KB
testcase_19 AC 9 ms
4,956 KB
testcase_20 AC 9 ms
4,832 KB
testcase_21 AC 8 ms
4,932 KB
testcase_22 AC 9 ms
4,864 KB
testcase_23 AC 10 ms
4,760 KB
testcase_24 AC 9 ms
5,044 KB
testcase_25 AC 9 ms
5,032 KB
testcase_26 AC 9 ms
4,948 KB
testcase_27 AC 9 ms
5,012 KB
testcase_28 AC 9 ms
4,856 KB
testcase_29 AC 9 ms
4,960 KB
testcase_30 AC 9 ms
4,972 KB
testcase_31 AC 10 ms
4,944 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) {
		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