結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-10-14 02:25:40 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 577 bytes | 
| コンパイル時間 | 846 ms | 
| コンパイル使用メモリ | 70,144 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:50:55 | 
| 合計ジャッジ時間 | 1,391 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
コンパイルメッセージ
main.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main()
      | ^~~~
            
            ソースコード
#include<iostream>
#include<vector>
using namespace std;
bool isp[200001];
vector<int>A;
int h(int X)
{
	if(X<10)return X;
	int s=0;
	while(X)s+=X%10,X/=10;
	return h(s);
}
int cnt[10];
main()
{
	int K,N;
	cin>>K>>N;
	for(int i=2;i<=N;i++)isp[i]=true;
	for(int i=2;i<=N;i++)
	{
		if(isp[i])
		{
			if(i>=K)A.push_back(i);
			for(int j=i+i;j<=N;j+=i)isp[j]=false;
		}
	}
	int ans=-1,len=-1,L=0;
	for(int R=0;R<A.size();R++)
	{
		int r=h(A[R]);
		while(cnt[r]>0)
		{
			cnt[h(A[L++])]--;
		}
		cnt[r]++;
		if(len<=R-L+1)
		{
			len=R-L+1;
			ans=A[L];
		}
	}
	cout<<ans<<endl;
}
            
            
            
        