結果

問題 No.6 使いものにならないハッシュ
ユーザー tarakojo1019tarakojo1019
提出日時 2021-01-18 17:14:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,889 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 123,764 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 23:28:47
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };



//素因数分解
template<typename T> void factorize(T n, std::vector<std::pair<T, int>>& ans) {
	for (T i = 2; i * i <= n; ++i) {
		if (n % i != 0) continue;
		ans.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			ans.back().second++;
		}
	}
	if (n != 1) ans.emplace_back(n, 1);
}


int main() {

	ll K, N; cin >> K >> N;
	vector<bool> E(N + 1, true);
	E[0] = false;
	E[1] = false;
	REP(i, 2, N + 1) {
		if (!E[i]) continue;
		for (int j = 2; j * i <= N; ++j) E[j * i] = false;
	}
	vector<ll> P;
	REP(i, 0, N + 1) if (E[i] && i >= K)P.push_back(i);

	vector<ll> S(P.size());
	REP(i, 0, P.size()) {
		ll s = P[i];
		do {
			ll tmp = 0;
			while (s > 0) tmp += s % 10, s /= 10;
			s = tmp;
		} while (s >= 10);
		S[i] = s;
	}

	ll ansn = 0;
	ll ansp = -1;
	REP(i, 0, P.size()) {
		unordered_set<ll> mp;
		for (int j = 0; j < 10 && i + j < P.size(); ++j) {
			if (mp.count(S[i + j]) != 0) break;
			mp.insert(S[i + j]);
		}
		if (ansn <= mp.size()) {
			ansn = mp.size();
			ansp = P[i];
		}
	}

	PRI(ansp);

	return 0;
}
0