結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | shu8Cream |
提出日時 | 2021-08-27 22:04:16 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 277 ms / 2,000 ms |
コード長 | 1,857 bytes |
コンパイル時間 | 2,230 ms |
コンパイル使用メモリ | 206,144 KB |
実行使用メモリ | 66,124 KB |
最終ジャッジ日時 | 2024-05-01 02:38:37 |
合計ジャッジ時間 | 9,671 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 267 ms
65,996 KB |
testcase_01 | AC | 260 ms
66,120 KB |
testcase_02 | AC | 269 ms
65,996 KB |
testcase_03 | AC | 274 ms
65,992 KB |
testcase_04 | AC | 264 ms
65,992 KB |
testcase_05 | AC | 259 ms
65,996 KB |
testcase_06 | AC | 260 ms
66,120 KB |
testcase_07 | AC | 260 ms
66,120 KB |
testcase_08 | AC | 268 ms
65,996 KB |
testcase_09 | AC | 262 ms
65,996 KB |
testcase_10 | AC | 274 ms
65,996 KB |
testcase_11 | AC | 270 ms
65,988 KB |
testcase_12 | AC | 261 ms
66,124 KB |
testcase_13 | AC | 259 ms
66,120 KB |
testcase_14 | AC | 267 ms
66,124 KB |
testcase_15 | AC | 267 ms
65,992 KB |
testcase_16 | AC | 267 ms
65,992 KB |
testcase_17 | AC | 263 ms
66,124 KB |
testcase_18 | AC | 267 ms
65,996 KB |
testcase_19 | AC | 270 ms
66,124 KB |
testcase_20 | AC | 268 ms
66,120 KB |
testcase_21 | AC | 277 ms
65,992 KB |
testcase_22 | AC | 266 ms
66,124 KB |
testcase_23 | AC | 272 ms
65,992 KB |
ソースコード
/** * 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; }