結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2022-11-09 11:10:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 828 bytes |
コンパイル時間 | 1,675 ms |
コンパイル使用メモリ | 168,608 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-22 17:20:26 |
合計ジャッジ時間 | 5,395 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 13 RE * 20 |
ソースコード
#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; }