結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー NoviNovi
提出日時 2021-10-13 23:58:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 864 bytes
コンパイル時間 5,772 ms
コンパイル使用メモリ 260,604 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 19:15:40
合計ジャッジ時間 20,187 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 TLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 5 ms
4,348 KB
testcase_12 TLE -
testcase_13 AC 758 ms
4,348 KB
testcase_14 AC 1,070 ms
4,348 KB
testcase_15 AC 1,391 ms
4,348 KB
testcase_16 AC 313 ms
4,348 KB
testcase_17 AC 59 ms
4,348 KB
testcase_18 AC 156 ms
4,348 KB
testcase_19 TLE -
testcase_20 AC 565 ms
4,348 KB
testcase_21 TLE -
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 282 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define ALL(a) (a).begin(), (a).end()

bool is_prime(int x) {
    if (x == 1) return false;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
    int l, r;
    cin >> l >> r;
    // b-a=kとして,k=0,1を調べればよい
    // p=a, p=2a+1のどちらかになる
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (is_prime(i)) ans++;
        if (is_prime(2 * i + 1)) ans++;
    }
    cout << ans << "\n";
}
0