結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー けーむけーむ
提出日時 2020-05-12 10:57:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 439 ms / 1,000 ms
コード長 1,853 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 176,804 KB
実行使用メモリ 8,732 KB
最終ジャッジ日時 2023-10-11 04:53:00
合計ジャッジ時間 7,226 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 39 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 407 ms
8,732 KB
testcase_06 AC 199 ms
5,704 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 3 ms
4,356 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 43 ms
4,352 KB
testcase_20 AC 129 ms
4,384 KB
testcase_21 AC 22 ms
4,352 KB
testcase_22 AC 23 ms
4,348 KB
testcase_23 AC 80 ms
4,548 KB
testcase_24 AC 94 ms
4,544 KB
testcase_25 AC 216 ms
5,680 KB
testcase_26 AC 181 ms
5,808 KB
testcase_27 AC 6 ms
4,352 KB
testcase_28 AC 71 ms
4,412 KB
testcase_29 AC 201 ms
5,732 KB
testcase_30 AC 20 ms
4,348 KB
testcase_31 AC 171 ms
5,552 KB
testcase_32 AC 204 ms
5,684 KB
testcase_33 AC 439 ms
8,660 KB
testcase_34 AC 438 ms
8,640 KB
testcase_35 AC 385 ms
8,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct isPrime {
private:
    vector<bool> data;
    
public:
    isPrime() {}
    isPrime(int n) {
        data.resize(n + 1, true);
        data[0] = data[1] = false;
        for(long long i = 2; (i * i) <= n; i++) {
            if (!data[i]) continue;
            for(long long j = 2; (i * j) <= n; j++) {
                data[i * j] = false;
            }
        }
    }
    
    bool is_prime(int n) {
        return data[n];
    }
    
    vector<int> get_primes_vector() {
        vector<int> ans;
        int n = data.size();
        for(int i = 0; i < n; i++) {
            if (data[i]) ans.push_back(i);
        }
        return ans;
    }
    
    set<int> get_primes_set() {
        set<int> ans;
        int n = data.size();
        for(int i = 0; i < n; i++) {
            if (data[i]) ans.insert(i);
        }
        return ans;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, l;
    cin >> n >> l;
    isPrime ip(l);
    auto pv = ip.get_primes_vector();
    ll ans = 0;
    rep(i, l - n + 1) {
        ll mv = (l - i) / (n - 1);
        auto it = upper_bound(all(pv), mv);
        if (it != pv.begin()) {
            ans += it - pv.begin();
        }
        // printf("i=%lld, mv=%lld, ans=%lld\n", i, mv, ans);
    }
    cout << ans << endl;
    return 0;
}
0