結果

問題 No.6 使いものにならないハッシュ
ユーザー A8pfA8pf
提出日時 2018-10-03 11:37:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,512 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 69,044 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:12:30
合計ジャッジ時間 1,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

int crypt(int num)
{
	int ret=0;
	while(1)
	{
		ret=0;
		while(num!=0)
		{
			ret+=num%10;
			num/=10;
		}
		if(ret<10)
			break;
		else
			num=ret;
	}
	return ret;
}

bool prime[200005];

int main()
{
	int n,k;
	vector<pair<int,int>> kou;
	int ans=0;
	cin>>k>>n;
	//エラトステネスのふるい
	fill(prime,prime+200005,true);
	prime[0]=false;
	prime[1]=false;
	for(int i=2;i<200005;i++)
	{
		if(prime[i])
		{
			for(int j=i*2;j<200005;j+=i)
				prime[j]=false;
		}
	}
	//k以上n以下の範囲の素数とそのハッシュを取り出す
	for(int i=k;i<n+1;i++)
	{
		if(prime[i])
			kou.push_back(make_pair(i,crypt(i)));
	}
	
	bool f[10];//0から9までどのくらい使われたか
	int cnt=0;//最大カウント
	int pos=0;//最大の最初の位置
	int i=0;
	/*
	for(int i=0;i<kou.size();i++)
		cerr<<kou[i].first<<" "<<kou[i].second<<endl;*/
	int c=0;
	int p=i;
	fill(f,f+10,false);
	while(i<kou.size())
	{
		//cerr<<p<<" "<<c<<endl;
		while(!f[kou[i].second])
		{
			f[kou[i].second]=true;
			c++;
			i++;
			if(i==kou.size())
				break;
		}
		if(c>=cnt)
		{
			cnt=c;
			pos=p;
		}
		//しゃくとり
		if(i<kou.size())
		{
			for(int j=p;j<i+1;j++)
			{
				f[kou[j].second]=false;
				c--;
				if(kou[j].second==kou[i].second)
				{
					p=j+1;
					break;
				}
			}
		}
	}
	cout<<kou[pos].first<<endl;
	return 0;
}
0