結果

問題 No.6 使いものにならないハッシュ
ユーザー y_mazuny_mazun
提出日時 2015-04-17 02:37:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 971 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 53,004 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 22:50:10
合計ジャッジ時間 1,880 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int k = getInt();
  const int n = getInt();

  vector<int> p;
  vector<int> h;

  for(int i = max(2, k); i <= n; i++){
    bool ok = true;
    for(int j = 2; j * j <= i; j++)
      if(i % j == 0){ ok = false; break; }
    if(!ok) continue;
    p.push_back(i);
    int hh = i;
    while(hh >= 10){
      int t = 0;
      while(hh){ t += hh % 10; hh /= 10; }
      hh = t;
    }
    h.push_back(hh);
  }

  int len = 0;
  int ans = 0;

  int fst = 0;

  set<int> s;
  REP(i,p.size()){
    if(s.count(h[i])){
      do{
        s.erase(h[fst]);
      }while(h[fst++] != h[i]);
    }
    s.insert(h[i]);
    // printf("%d(%d): %d\n", p[i], h[i], p[fst]);
    if(len <= i - fst + 1){
      len = i - fst + 1;
      ans = p[fst];
    }
  }

  printf("%d\n", ans);

  return 0;
}
0