結果
| 問題 |
No.1657 Sum is Prime (Easy Version)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-27 22:04:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 212 ms / 2,000 ms |
| コード長 | 1,857 bytes |
| コンパイル時間 | 2,180 ms |
| コンパイル使用メモリ | 198,880 KB |
| 最終ジャッジ日時 | 2025-01-24 03:04:56 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
/**
* 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;
}