結果

問題 No.6 使いものにならないハッシュ
ユーザー msm1993msm1993
提出日時 2019-04-16 12:58:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,905 bytes
コンパイル時間 2,645 ms
コンパイル使用メモリ 155,492 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 23:16:36
合計ジャッジ時間 3,469 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

const int MAX_N = 1000010;
vector<int> prime;
bool is_prime[MAX_N];

int sieve(int n) {
  for (int i = 0; i <= n; i++) is_prime[i] = true;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.push_back(i);
      for (int j = i*i; j <= n; j += i) is_prime[j] = false;
    }
  }
  return prime.size();
}

int K, N;
vector<int> v, ps;

int calc(int x) {
  if (x / 10 == 0) return x;
  int r = 0;
  while (x) {
    r += x % 10;
    x /= 10;
  }
  return calc(r);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> K >> N;
  sieve(N);
  for (int p : prime) {
    if (K <= p && p <= N) {
      v.EB(calc(p));
      ps.EB(p);
    }
  }
  int l = 0, r = 0;
  int n = SZ(v);
  int mx = 0;
  int ans = -1;
  set<int> st;
  while (l < n) {
    while (r < n && st.count(v[r]) == 0) {
      st.insert(v[r]);
      r++;
    }
    if (r-l >= mx) {
      ans = ps[l];
      mx = r-l;
    }
    st.erase(v[l]);
    l++;
  }
  cout << ans << endl;

  return 0;
}
0