結果

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

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>

#include <algorithm>
#include <cmath>

#include <string>
#include <array>
#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;
//int primeSize=0;
int hashSize = 0;

bool pdp[NumMax+1];
vector<int> prime;
array<int,NumMax> hashList;

void makePrime(int N){
	for(int i=2; i<= N; ++i){
		if(pdp[i] == false){
			prime.push_back(i);
			for(int j = i+i; j<= N; j += i){
				pdp[j] = true;
			}
		}
	}
	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<prime.size();++i){
		{
			//hashList.push_back( makehash( prime[i] ) );
			hashList[hashSize] = makehash( prime[i] );
			++hashSize;
		}
	}
}
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 < prime.size() ; ++No){
		if(prime[No] < K){
			++i;
		}else{
			break;
		}
	}

	for(i; i < hashSize ; ++i){
		set<int> data;
		for(unsigned int j = i;j < hashSize ; ++j){
			if( data.insert(hashList[j]).second != true){
				break;
			}
		}
		if( maxLen <= data.size() ){
			maxLen = data.size();
			ans = prime[i];
		}
	}
	P(ans);
    return 0;
}
0