結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー kappybarkappybar
提出日時 2021-09-23 12:15:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 165,636 KB
実行使用メモリ 11,104 KB
最終ジャッジ日時 2023-09-18 19:51:23
合計ジャッジ時間 3,399 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
11,036 KB
testcase_01 AC 24 ms
10,844 KB
testcase_02 AC 28 ms
10,868 KB
testcase_03 AC 25 ms
10,776 KB
testcase_04 AC 22 ms
10,772 KB
testcase_05 AC 25 ms
10,856 KB
testcase_06 AC 23 ms
10,768 KB
testcase_07 AC 22 ms
10,764 KB
testcase_08 AC 22 ms
10,764 KB
testcase_09 AC 23 ms
10,848 KB
testcase_10 AC 23 ms
10,816 KB
testcase_11 AC 23 ms
10,728 KB
testcase_12 AC 26 ms
10,904 KB
testcase_13 AC 25 ms
10,856 KB
testcase_14 AC 25 ms
11,012 KB
testcase_15 AC 26 ms
10,756 KB
testcase_16 AC 26 ms
11,104 KB
testcase_17 AC 25 ms
10,704 KB
testcase_18 AC 23 ms
10,868 KB
testcase_19 AC 28 ms
10,768 KB
testcase_20 AC 25 ms
10,832 KB
testcase_21 AC 29 ms
10,764 KB
testcase_22 AC 24 ms
11,024 KB
testcase_23 AC 25 ms
10,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcountll(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    int mx = 2000005;
    int L,R;
    cin >> L >> R;

    vector<int> isprime(mx+1,-1);
    isprime[0] = isprime[1] = -1;
    for(int i=2;i<=mx;i++){
        if (isprime[i] == -1) {
            isprime[i] = i;
            for(int j=2*i;j<=mx;j+=i){
                isprime[j] = i;
            }
        }
    }

    int ans = 0;
    for(int i=L;i<=R;i++){
        if (isprime[i] == i) ++ans;
        if (i < R && isprime[2*i+1] == 2*i+1) ++ans;
    }
    cout << ans << endl;
    return 0;
}
0