結果

問題 No.6 使いものにならないハッシュ
ユーザー tai96tai96
提出日時 2015-02-21 21:20:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 65,212 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:49:25
合計ジャッジ時間 1,636 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 3 ms
4,356 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 3 ms
4,352 KB
testcase_23 AC 3 ms
4,352 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 3 ms
4,356 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,352 KB
testcase_31 AC 2 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

typedef std::pair<int, int> P;
const int max = 200001;

bool isPrime[max];
std::vector<P> v;

void init(){
	memset(isPrime, -1, sizeof(isPrime));

	isPrime[0] = false;
	isPrime[1] = false;

	for (int i = 2; i*i <= max; i++){
		if (!isPrime[i])continue;
		for (int j = i * 2; j < max; j += i)isPrime[j] = false;
	}

	for (int i = 2; i < max; i++){
		if (isPrime[i])v.push_back(P(i, i % 9));
	}
}

int main(){
	init();

	int n, k;
	std::cin >> n >> k;

	int s = 0, e = v.size() - 1;
	while (v[s].first < n)s++;
	while (v[e].first > k)e--;

	int ans = 0, max_size = 0;

	for (int i = e; i >= s; i--){
		int cnt[9], size = 0;
		memset(cnt, 0, sizeof(cnt));

		int j = 0;
		while (cnt[v[i + j].second] == 0 && i + j <= e){
			cnt[v[i + j].second]++;
			size++;
			j++;
		}
		if (size > max_size)ans = v[i].first, max_size = size;
	}

	std::cout << ans << std::endl;

	return 0;
}
0