結果

問題 No.6 使いものにならないハッシュ
ユーザー ldsyb
提出日時 2017-06-16 18:03:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 850 bytes
コンパイル時間 687 ms
コンパイル使用メモリ 71,296 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-10-01 06:48:49
合計ジャッジ時間 4,770 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int32_t> make_primes(int32_t a, int32_t b){
	vector<int32_t> ps;
	if(a <= 2 && 2 <= b) ps.emplace_back(2);
	if(a <= 3 && 3 <= b) ps.emplace_back(3);
	a = max(5, a);
	for(; a <= b; a++){
		bool f = true;
		for(int32_t i = 2; i * i <= a; i++) f &= !!(a % i);
		if(f) ps.emplace_back(a);
	}
	return ps;
}

int main(){
	int32_t k, n;
	cin >> k >> n;
	auto hashed = make_primes(k, n), ps = hashed;
	for(auto& p:hashed) while(10 <= p) p = p / 10 + p % 10;
	bool used[10]{};
	int32_t ans = 0, maxsize = 0, l = 0, r = 0;
	while(l < hashed.size() && r < hashed.size()){
		if(used[hashed[r]]){
			while(hashed[l] != hashed[r]) l++;
			l++;
			r++;
		}else used[hashed[r++]] = true;
		if(maxsize <= r - l && l < hashed.size()){
			maxsize = r - l;
			ans = ps[l];
		}
	}
	cout << ans << endl;
}
0