結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー shu8Creamshu8Cream
提出日時 2021-08-27 22:04:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,857 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 204,316 KB
実行使用メモリ 67,692 KB
最終ジャッジ日時 2023-08-13 09:02:27
合計ジャッジ時間 8,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 204 ms
65,860 KB
testcase_01 AC 207 ms
67,692 KB
testcase_02 AC 214 ms
66,116 KB
testcase_03 AC 207 ms
66,488 KB
testcase_04 AC 207 ms
66,164 KB
testcase_05 AC 212 ms
67,344 KB
testcase_06 AC 220 ms
67,504 KB
testcase_07 AC 209 ms
66,976 KB
testcase_08 AC 208 ms
66,540 KB
testcase_09 AC 210 ms
66,900 KB
testcase_10 AC 210 ms
66,552 KB
testcase_11 AC 205 ms
66,412 KB
testcase_12 AC 214 ms
66,788 KB
testcase_13 AC 217 ms
67,344 KB
testcase_14 AC 218 ms
65,960 KB
testcase_15 AC 218 ms
65,800 KB
testcase_16 AC 210 ms
66,328 KB
testcase_17 AC 218 ms
66,696 KB
testcase_18 AC 216 ms
66,488 KB
testcase_19 AC 215 ms
66,072 KB
testcase_20 AC 211 ms
66,288 KB
testcase_21 AC 212 ms
66,572 KB
testcase_22 AC 212 ms
66,044 KB
testcase_23 AC 208 ms
67,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
*    author:  shu8Cream
*    created: 27.08.2021 21:19:26
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define rrep(i,n) for (int i=(n-1); i>=0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}

struct Sieve{
    int n;
    vector<int> f,primes;
    Sieve(int n=1):n(n+1),f(n+1){
        f[0] = f[1] = -1;
        for(ll i=2; i<=n; ++i){
            if(f[i]) continue;
            primes.push_back(i);
            f[i]=i;
            for(ll j=i*i; j<=n; j+=i){
                if(!f[j]) f[j]=i;
            }
        }
    }

    bool isPrime(int x){ return f[x]==x;}

    vector<int> factorList(int x){
        vector<int> res;
        while(x!=1){
            res.push_back(f[x]);
            x/=f[x];
        }
        return res;
    }

    vector<P> factor(int x){
        vector<int> fl = factorList(x);
        if(fl.size()==0) return {};
        vector<P> res(1,P(fl[0], 0));
        for(int p : fl){
            if(res.back().first == p){
                res.back().second++;
            }else{
                res.emplace_back(p,1);
            }
        }
        return res;
    }

    vector<int> prime(){
        return primes;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Sieve sieve(15001000);
    ll l,r; cin >> l >> r;
    ll ans = 0;
    for(int i=l+1; i<=r; i++){
        if(sieve.isPrime(i+i-1)) ans++;
        if(sieve.isPrime(i)) ans++;
    }
    if(sieve.isPrime(l))ans++;
    cout << ans << endl;
}
0