結果

問題 No.6 使いものにならないハッシュ
ユーザー cureskolcureskol
提出日時 2020-03-27 08:56:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 562 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 168,424 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:22:49
合計ジャッジ時間 2,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 25 ms
4,352 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 6 ms
4,352 KB
testcase_05 AC 6 ms
4,352 KB
testcase_06 AC 13 ms
4,352 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 AC 16 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 13 ms
4,348 KB
testcase_16 AC 10 ms
4,352 KB
testcase_17 AC 19 ms
4,348 KB
testcase_18 AC 24 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 16 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 18 ms
4,352 KB
testcase_23 AC 15 ms
4,352 KB
testcase_24 AC 17 ms
4,348 KB
testcase_25 AC 9 ms
4,348 KB
testcase_26 AC 20 ms
4,352 KB
testcase_27 AC 15 ms
4,348 KB
testcase_28 AC 9 ms
4,348 KB
testcase_29 AC 22 ms
4,348 KB
testcase_30 AC 19 ms
4,348 KB
testcase_31 AC 17 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int f(int a){
  if(a<10)return a;
  int res=0;
  while(a){
    res+=a%10;
    a/=10;
  }
  return f(res);
}
bool prime(int a){
  if(a<2)return 0;
  for(int i=2;i*i<=a;i++)if(a%i==0)return 0;
  return 1;
}

signed main(){
  int k,n;cin>>k>>n;
  int mx=0,ans=0,now=0;
  vector<int> v(10,0);
  vector<int> w;
  for(int i=k;i<=n;i++)if(prime(i))w.push_back(i);
  for(int j=0;j<w.size();j++){
    int a=f(w[j]);
    while(v[a])v[f(w[now++])]--;
    v[a]++;
    if(mx<=j-now)mx=j-now,ans=w[now];
  }
  cout<<ans<<endl;
}
0