結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  commy | 
| 提出日時 | 2018-08-12 18:09:01 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 5 ms / 5,000 ms | 
| コード長 | 1,509 bytes | 
| コンパイル時間 | 840 ms | 
| コンパイル使用メモリ | 75,772 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:44:51 | 
| 合計ジャッジ時間 | 1,816 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
using namespace std;
typedef long long int lli;
template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
int hsh(int n) {
    while (n >= 10) {
        int sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
        n = sum;
    }
    return n;
}
int main() {
    int N, K;
    cin >> K >> N;
    vector<bool> isPrime(N + 1, true);
    isPrime[0] = isPrime[1] = false;
    vector<int> Prime;
    vector<int> Phash;
    REP(i, 2, N + 1) {
        if (isPrime[i]) {
            if (i >= K) {
                Prime.push_back(i);
                Phash.push_back(hsh(i));
            }
            for (int j = i * 2; j <= N; j += i) {
                isPrime[j] = false;
            }
        }
    }
    vector<bool> used(10, false);
    int ans = 0;
    int r = 0;
    int cnt = 0;
    REP(i, 0, Prime.size()) {
        while (r < Prime.size() && !used[Phash[r]]) {
            used[Phash[r]] = true;
            r++;
        }
        if (cnt <= r - i) {
            ans = Prime[i];
            cnt = r - i;
        }
        used[Phash[i]] = false;
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        