結果

問題 No.6 使いものにならないハッシュ
ユーザー hotpepsihotpepsi
提出日時 2015-02-15 18:59:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,044 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 62,704 KB
実行使用メモリ 4,408 KB
最終ジャッジ日時 2023-10-14 22:48:57
合計ジャッジ時間 1,727 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

using namespace std;

static int get_hash(int n) {
	if (n < 10) {
		return n;
	}
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return get_hash(sum);
}

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	int K = atoi(s.c_str());
	getline(cin, s);
	int N = atoi(s.c_str());
	static int f[200001] = {};
	static int p[200001] = {};
	static int h[200001] = {};
	int primes = 0;
	int pos[10] = {};
	int mx[11] = {};
	int count = 0;
	int max_count = 0;
	int ans = 0;
	for (int i = 2; i <= N; ++i) {
		if (!f[i]) {
			for (int j = i * 2; j <= N; j += i) {
				f[j] = 1;
			}
			if (i >= K) {
				++count;
				int hash = get_hash(i);
				p[primes] = i;
				h[primes] = hash;
				++primes;
				int c = primes - mx[hash];
				if (c < count) {
					count = c;
				}
				if (count >= max_count) {
					max_count = count;
					ans = p[primes - count];
				}
				mx[hash] = primes;
			}
		}
	}

	cout << ans << endl;
	return 0;
}
0