結果

問題 No.6 使いものにならないハッシュ
ユーザー opqopq_opqopq_
提出日時 2015-04-30 12:57:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,134 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 62,536 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:51:31
合計ジャッジ時間 1,865 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
using namespace std;

#define N_MAX 200000

int K, N;
bool isnotprime[N_MAX + 10000];
vector<pair<int, int>> mask;

void make_prime() {
	isnotprime[0] = isnotprime[1] = 1;
	for (int i = 2; i * i <= N_MAX; i++) {
		if (!isnotprime[i]) {
			for (int j = i * i; j <= N_MAX; j += i) {
				isnotprime[j] = 1;
			}
		}
	}
}

void make_mask() {
	for (int i = 2; i <= N_MAX; i++) {
		if (!isnotprime[i]) {
			int x = i;
			while (9 < x) {
				int tmp = x;
				x = 0;
				while (tmp) {
					x += tmp % 10;
					tmp /= 10;
				}
			}
			mask.emplace_back(i, 1 << x - 1);
		}
	}
}

int main() {
	make_prime();
	make_mask();
	
	cin >> K >> N;
	
	int len_max = 0, res = 0;
	
	auto it = lower_bound(mask.begin(), mask.end(), make_pair(K, 0));
	while (it != mask.end()) {
		if (N < it->first) break;
		int bit = 0, len = 0;
		for (auto jt = it; jt != mask.end(); jt++) {
			if (bit & jt->second || N < jt->first) {
				if (len_max <= len) {
					len_max = len;
					res = it->first;
				}
				break;
			}
			bit |= jt->second;
			len++;
		}
		it++;
	}
	
	cout << res << '\n';
	
	return 0;
}

0