結果

問題 No.6 使いものにならないハッシュ
ユーザー pocaristpocarist
提出日時 2015-09-02 13:32:42
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,424 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 84,532 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-25 22:08:40
合計ジャッジ時間 3,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;

vector<int> primes(int n)
{
	vector<bool> table(n + 1, true);
	table[0] = table[1] = false;
	int mid = (int)floor(sqrt(n));
	for (int i = 2; i <= mid; i++) {
		if (table[i]) {
			for (int j = i+i; j <= n; j += i)
				table[j] = false;
		}
	}
	vector<int> ans;
	for (int i = 2; i <= n; i++)
		if (table[i])
			ans.push_back(i);
	return ans;
}

int sum_digit(int n)
{
	int i = n;
	int acc = 0;
	for (;;) {
		int m = i % 10;
		int d = i / 10;
		acc += m;
		if (d == 0) {
			if (acc < 10) {
				break;
			} else {
				i = acc;
				acc = 0;
			}
		} else {
			i = d;
		}
	}
	return acc;
}

int main()
{
	int K, N;
	cin >> K >> N;
	vector<int> ps = primes(N);
	ps.erase(remove_if(ps.begin(), ps.end(), [K](int x) {return x < K; }));
	vector<int> ss(ps.size());
	transform(ps.begin(), ps.end(), ss.begin(), sum_digit);
	
	int len = ps.size();
	int ans = 0;
	int ans_len = 0;
	for (int i = 0; i < len; i++) {
		set<int> ks;
		ks.insert(ss[i]);
		int tmp = ps[i];
		int tmp_len = 1;
		for (int j = i+1; j < len; j++) {
			if (ks.find(ss[j]) != ks.end()) {
				if (tmp_len <= (int)ks.size()) {
					tmp_len = ks.size();
				}
				break;
			} else {
				ks.insert(ss[j]);
			}
		}
		if (ans_len <= tmp_len) {
			ans_len = tmp_len;
			ans = tmp;
		}
	}
	cout << ans << endl;
	return 0;
}
0