結果

問題 No.6 使いものにならないハッシュ
ユーザー IL_mstaIL_msta
提出日時 2015-07-08 15:37:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 1,705 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 93,064 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 22:53:10
合計ジャッジ時間 6,337 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 269 ms
4,348 KB
testcase_03 AC 14 ms
4,348 KB
testcase_04 AC 46 ms
4,352 KB
testcase_05 AC 31 ms
4,348 KB
testcase_06 AC 137 ms
4,348 KB
testcase_07 AC 122 ms
4,352 KB
testcase_08 AC 144 ms
4,348 KB
testcase_09 AC 253 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 14 ms
4,348 KB
testcase_12 AC 131 ms
4,352 KB
testcase_13 AC 215 ms
4,352 KB
testcase_14 AC 223 ms
4,348 KB
testcase_15 AC 104 ms
4,348 KB
testcase_16 AC 207 ms
4,352 KB
testcase_17 AC 257 ms
4,348 KB
testcase_18 AC 257 ms
4,352 KB
testcase_19 AC 235 ms
4,348 KB
testcase_20 AC 164 ms
4,348 KB
testcase_21 AC 6 ms
4,352 KB
testcase_22 AC 210 ms
4,348 KB
testcase_23 AC 139 ms
4,348 KB
testcase_24 AC 179 ms
4,348 KB
testcase_25 AC 124 ms
4,352 KB
testcase_26 AC 234 ms
4,348 KB
testcase_27 AC 208 ms
4,348 KB
testcase_28 AC 69 ms
4,352 KB
testcase_29 AC 235 ms
4,348 KB
testcase_30 AC 176 ms
4,352 KB
testcase_31 AC 183 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>

/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
const int NumMax = 200000;
int prime[NumMax];
int primeMax=0;
vector<int> hashList;

void makePrime(int N){
	int i,j;
	bool f;
	for(i=2; i<=N; ++i){
		f = true;
		for(j=0;j<primeMax && prime[j] <= i/2;++j){
			if(i%prime[j] == 0){
				f = false;
				break;
			}
		}
		if(f == true){
			prime[primeMax] = i;
			++primeMax;
		}
	}
	return ;
}
int makehash(int num){
	int temp = num;
	int value = 0;
	do{
		while(temp != 0){
			value += temp%10;
			temp /= 10;
		}
		temp  = value;
		value = 0;
	}while(temp >= 10);
	return temp;
}
void makeHashList(int K,int N){
	for(int i=0;i<primeMax;++i){
		//if( prime[i] >= K)
		{
			hashList.push_back( makehash( prime[i] ) );
		}
	}
}
int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    cout << setprecision(10);//

	int K,N;
	cin>>K>>N;
	makePrime(N);
	makeHashList(K,N);
	//hashList
	unsigned int maxLen=0;
	int ans = 0;
	unsigned int i=0;
	for(int No=0;No<primeMax;++No){
		if(prime[No] < K){
			++i;
		}
	}
	for(i;i< hashList.size();++i){
		set<int> data;
		for(unsigned int j=i;j<hashList.size();++j){
			if( data.insert(hashList[j]).second != true){
				break;
			}
		}
		if( maxLen <= data.size() ){
			maxLen = data.size();
			ans = prime[i];
		}
	}
	P(ans);
    return 0;
}
0