結果
| 問題 | No.6 使いものにならないハッシュ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-15 23:29:05 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 975 bytes |
| 記録 | |
| コンパイル時間 | 3,647 ms |
| コンパイル使用メモリ | 338,160 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-15 23:29:11 |
| 合計ジャッジ時間 | 5,306 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3E5+10;
bool is_prime[N];
int hsh[N];
void solve(){
int L,R;cin>>L>>R;
is_prime[2]=1;
for(int i=3;i<=R;i+=2)is_prime[i]=1;
const int M=sqrt(R+1e-7);
for(int i=3;i<=M;++++i){
if(is_prime[i]){
for(int j=(ll)i*i;j<=R;j+=i+i){
is_prime[j]=0;
}
}
}
vector<int> prime;
for(int i=L;i<=R;++i){
if(!is_prime[i])continue;
hsh[prime.size()]=1+(i-1)%9;
prime.emplace_back(i);
}
const int N=prime.size();
int ans=0,fir=-1;
vector<int> cnt(10);
for(int L=0,R=0;L<N;++L){
while(R<N&&cnt[hsh[R]]==0)++cnt[hsh[R++]];
if(ans<=R-L){
ans=R-L;
fir=prime[L];
}
cnt[hsh[L]]--;
}
cout<<fir<<endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);
int T=1; //cin>>T;
while(T--)solve();
return 0;
}