結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2022-11-09 11:10:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 828 bytes |
コンパイル時間 | 1,880 ms |
コンパイル使用メモリ | 166,992 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-22 17:21:21 |
合計ジャッジ時間 | 2,636 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
#include "bits/stdc++.h"using namespace std;const int N=200010;int a,b,c,p[N],h[N],is_p[N],l,ans,vis[20];int h0(int n) {while (n>=10) {int m=0;while (n) m+=n%10,n/=10;n=m;}return n;}int main() {memset(is_p,0x3f,sizeof(is_p));is_p[0]=is_p[1]=0;for (int i=2;i*i<N;++i)if (is_p[i])for (int j=i*i;j<N;j+=i)is_p[j]=0;cin>>a>>b;for (int i=a;i<=b;++i)if (is_p[i]) ++c,p[c]=i,h[c]=h0(i);assert(c>=1);for (int i=1,j=2;i<=c;++i) {vis[h[i]]=1;if (i==j) ++j;while (j<=c) {if (vis[h[j]]) break;vis[h[j]]=1;++j;}if (l<=j-i) l=j-i,ans=p[i];if (j>c) break;vis[h[i]]=0;}cout<<ans<<endl;return 0;}