結果

問題 No.6 使いものにならないハッシュ
ユーザー t_mkt_mk
提出日時 2022-03-17 11:43:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 176,740 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 14:39:53
合計ジャッジ時間 3,198 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 8 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 6 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 6 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 5 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 8 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 6 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 6 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 7 ms
6,676 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 5 ms
6,676 KB
testcase_29 AC 7 ms
6,676 KB
testcase_30 AC 7 ms
6,676 KB
testcase_31 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
using ll = long long;
using P =pair<int,int>;
ll INF = 1LL << 60;
int ans[210000];
vector<int> isprime(210000,1);
int dfs(int p){
  if(ans[p] != 0)return ans[p];
  if(p < 10)return ans[p] = p;
  int s = p;
  int sum = 0;
  while(s > 0){
    sum += (s % 10);
    s /= 10;
  }
  return ans[p] = dfs(sum);
}
int main(){
  int k,n;
  cin >> k >> n;
  isprime[1] = 0;
  for(int i = 2;i <= n;i++){
    if(isprime[i] == 0)continue;
    for(int j = 2*i; j <= n;j+=i){
      isprime[j] = 0;
    }
  }
  vector<P> hash;
  for(int i = k;i <= n;i++){
    if(isprime[i]){
      hash.push_back(P(dfs(i),i));
    }
  }
  int res = 0;
  int ans2 = 0;
  for(int i = 0;i < hash.size();i++){
    set<int> st;
    int cnt = i;
    while(cnt < hash.size()){
      st.insert(hash[cnt].first);
      if(st.size() != (cnt - i + 1)){
        cnt --;break;
      }
      cnt++;
    }
    cnt = st.size();
    if(res <= cnt){
      res = cnt;
      ans2 = hash[i].second;
    }
  }
  cout << ans2 << endl;
}
0