結果

問題 No.6 使いものにならないハッシュ
コンテスト
ユーザー pessimist
提出日時 2026-01-15 23:26:56
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 973 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,332 ms
コンパイル使用メモリ 338,288 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-15 23:27:02
合計ジャッジ時間 4,864 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
}
0