結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | Sooh317 |
提出日時 | 2021-08-27 21:34:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,923 bytes |
コンパイル時間 | 2,308 ms |
コンパイル使用メモリ | 212,840 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-21 01:05:38 |
合計ジャッジ時間 | 3,679 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
6,816 KB |
testcase_01 | AC | 19 ms
6,816 KB |
testcase_02 | AC | 24 ms
6,820 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 20 ms
6,816 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 20 ms
6,816 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 20 ms
6,816 KB |
testcase_12 | AC | 24 ms
6,820 KB |
testcase_13 | AC | 22 ms
6,820 KB |
testcase_14 | AC | 23 ms
6,816 KB |
testcase_15 | AC | 22 ms
6,816 KB |
testcase_16 | AC | 20 ms
6,816 KB |
testcase_17 | AC | 20 ms
6,820 KB |
testcase_18 | AC | 20 ms
6,820 KB |
testcase_19 | AC | 24 ms
6,824 KB |
testcase_20 | AC | 21 ms
6,820 KB |
testcase_21 | AC | 25 ms
6,816 KB |
testcase_22 | AC | 20 ms
6,820 KB |
testcase_23 | AC | 21 ms
6,820 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //#include <atcoder/modint> //using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007; #pragma region template using ll = long long; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define rep1(n) for(ll i=0;i<n;++i) #define rep2(i,n) for(ll i=0;i<n;++i) #define rep3(i,a,b) for(ll i=a;i<b;++i) #define rep(...) overload3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define fi first #define se second #define debug(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;} std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;} template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; } #pragma endregion int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; const int inf = 1001001001; const ll INF = 1001001001001001001ll; // const double pi = acos(-1); //const ll mod = 998244353; const ll mod = 1000000007; struct Sieve { int MX; vector<bool> ip; // is prime vector<int> mu; // mobius vector<int> mf; // min factor Sieve(int _MX, bool factor = false, bool mobius = false):MX(_MX){ ip.resize(MX, true); if(factor) mf.resize(MX, 0); if(mobius) mu.resize(MX, 1); for(int i = 2; i < MX; i++){ if(!ip[i]) continue; ip[i] = true; if(factor) mf[i] = i; if(mobius) mu[i] = -1; for(int j = i+i; j < MX; j += i){ ip[j] = false; if(factor && mf[j] == 0) mf[j] = i; if(mobius){ if(j / i % i == 0) mu[j] = 0; else mu[j] = -mu[j]; } } } } vector<pair<int, int>> factorize(int n){ vector<pair<int, int>> res; int p = mf[n], e = 0; while(n != 1){ while(n % p == 0){ n /= p; ++e; } res.emplace_back(p, e); p = mf[n], e = 0; } return res; } /* make 1-indexed vectors */ // return F where F(i) = Σf(k) (i|k) template<class T> void fast_zeta(vector<T> &f){ int N = f.size(); for(int i = 2; i < N; i++){ if(!ip[i]) continue; for(int j = (N - 1)/i; j >= 1; --j) f[j] += f[i*j]; } } // return f where F(i) = Σf(k) (i|k) template<class T> void fast_mobius(vector<T> &F){ int N = F.size(); for(int i = 2; i < N; i++){ if(!ip[i]) continue; for(int j = 1; j <= (N - 1)/i; ++j) F[j] -= F[i*j]; } } // return h where h(k) = Σ f(i)*g(i) (gcd(i, j) = k) in O(NloglogN) template<class T> vector<T> gcd_convolution(const vector<T> &f, const vector<T> &g){ int N = max(f.size(), g.size()); vector<T> F(N), G(N), h(N); for(int i = 0; i < (int)f.size(); i++) F[i] = f[i]; for(int i = 0; i < (int)g.size(); i++) G[i] = g[i]; fast_zeta(F); fast_zeta(G); for(int i = 1; i < N; i++) h[i] = F[i] * G[i]; fast_mobius(h); return h; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); ll l, r; cin >> l >> r; Sieve s(2000100); // (a + b)(b - a + 1) / 2 int ans = 0; for(ll a = l; a <= r; a++){ // b - a + 1 = 2 iff b = a + 1 // b - a + 1 = 1 iff b = a if(a != 1 && s.ip[a]) ans++; if(s.ip[2*a + 1]) ans++; } cout << ans << endl; }