結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー keep_OCkeep_OC
提出日時 2021-08-27 21:55:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,121 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 167,632 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 08:48:04
合計ジャッジ時間 2,858 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 20 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 19 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 15 ms
4,384 KB
testcase_15 AC 15 ms
4,384 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 18 ms
4,384 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 22 ms
4,376 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 15 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;

typedef struct {
    int64_t to, weight;
} edge;

Int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
Int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};

template<class T> 
istream &operator>>(istream &is, vector<T> &v) { 
    for (auto &e : v) {
        is >> e; 
    }
    return is; 
}

bool print_space_enable = false;
void print() { 
    std::cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    std::cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

template<class T>
vector<T> make_vec(size_t n, T val) {
    return vector<T>(n, val);
}

template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

bool is_overflow(Int a, Int b) {
    return a > INF / b;
}

void solve() {
    Int l, r;
    cin >> l >> r;
    vector<bool> prime(2 * r + 1, true);
    prime[0] = prime[1] = false;
    for (Int i = 2; i <= 2 * r; i++) {
        if (prime[i]) {
            for (Int j = 2; i * j <= 2 * r; j++) {
                prime[i * j] = false;
            }
        }
    }
    Int res = 0;
    for (Int i = l; i <= r; i++) {
        if (prime[i]) {
            res++;
        }
    }
    for (Int i = l; i < r; i++) {
        if (prime[i + i + 1]) {
            res++;
        }
    }
    print(res);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    //Int _t; cin >> _t; while (_t--) solve();
    return 0;
}
0