結果

問題 No.6 使いものにならないハッシュ
ユーザー krotonkroton
提出日時 2014-11-01 05:33:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 78,820 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-29 00:05:14
合計ジャッジ時間 2,337 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
 
int h(int n){
	if(n == 0)return 0;
	if(n % 9 == 0)return 9;
 
	return n % 9;
}
 
bool isp[200010];
vector<int> getPrimes(int K, int N){
	for(int i=0;i<=N;i++)isp[i] = true;
 
	isp[0] = isp[1] = false;
	for(int p=2;p*p<=N;p++)if(isp[p]){
		for(int k=p*p;k<=N;k+=p)isp[k] = false;
	}
 
	vector<int> res;
	for(int i=K;i<=N;i++)if(isp[i])res.push_back(i);
 
	return res;
}
 
int main() {
	int K, N;
	cin >> K >> N;
 
	vector<int> primes = getPrimes(K, N);
 
	int maxi = 0;
	int res = 0;
	for(int i=0;i<primes.size();i++){
		set<int> used;
 
		int cnt = 0;
		for(int j=i;j<primes.size();j++){
			int hs = h(primes[j]);
			if(used.count(hs))break;
 
			used.insert(hs);
			++cnt;
		}
 
		if(cnt >= maxi){
			maxi = cnt;
			res = primes[i];
		}
	}
 
	cout << res << " " << maxi << endl;
	return 0;
}
0