結果

問題 No.6 使いものにならないハッシュ
ユーザー furon
提出日時 2023-05-21 15:46:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,765 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 131,676 KB
最終ジャッジ日時 2025-02-13 03:57:42
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;
vector<bool> Eratosthenes(int N) {
vector<bool> isPrime(N + 1, true);
isPrime[0] = isPrime[1] = false;
for (int p = 2; p * p <= N; ++p) {
if (!isPrime[p]) continue;
for (int q = p * 2; q <= N; q += p) {
isPrime[q] = false;
}
}
return isPrime;
}
ll sumDigits(ll x) {
int ret = 0;
do {
ret += x % 10;
x /= 10;
} while (x > 0);
return ret;
}
int f(int x) {
if (x < 10) return x;
return f(sumDigits(x));
}
int main() {
int k, n;
cin >> k >> n;
vb isPrime = Eratosthenes(n);
vpii p;
for (int i = k; i <= n; i++) {
if (isPrime[i]) {
p.push_back({ i, f(i) });
}
}
int ans = 0;
int maxsize = 0;
set<int> st;
int r = 0;
for (int l = 0; l < p.size(); l++) {
while (r < p.size() && st.find(p[r].second) == st.end()) {
st.insert(p[r].second);
r++;
}
if (st.size() >= maxsize) {
ans = p[l].first;
maxsize = st.size();
}
if (l == r) r++;
else st.erase(p[l].second);
}
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0