#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #include using namespace std; template struct cLtraits_identity{ using type = T; } ; template using cLtraits_try_make_signed = typename conditional< is_integral::value, make_signed, cLtraits_identity >::type; template struct cLtraits_common_type{ using tS = typename cLtraits_try_make_signed::type; using tT = typename cLtraits_try_make_signed::type; using type = typename common_type::type; } ; void*wmem; char memarr[96000000]; template inline auto min_L(S a, T b) -> typename cLtraits_common_type::type{ return (typename cLtraits_common_type::type) a <= (typename cLtraits_common_type::type) b ? a : b; } template inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } int Prime_L(int N, int res[], void *mem=wmem){ int i; int a; int b; int sz = 1; const int r = 23000; bool*isprime; int*sf; int ss = 1; walloc1d(&isprime, r, &mem); walloc1d(&sf, r, &mem); N /= 2; res[0] = 2; b =min_L(r, N); for(i=(1);i<(b);i++){ isprime[i] = 1; } for(i=(1);i<(b);i++){ if(isprime[i]){ res[sz++] = 2*i+1; sf[ss] = 2*i*(i+1); if(sf[ss] < N){ while(sf[ss] < r){ isprime[sf[ss]] = 0; sf[ss] += res[ss]; } ss++; } } } for(a=r; a= 1) || (m==-1 && fg >= 2)); assert(mn <= m * res && m * res <= mx); assert(!(res == 0 && m == -1)); assert(!(res != 0 && f == 0)); assert(!(res == 0 && fg >= 2)); assert(i == nx); return m * res; } void cReader_eof(){ int i; i = my_getchar_unlocked(); assert(i == EOF); } int ps; int p[2000000]; int main(){ int i; wmem = memarr; long long L; long long R; long long res = 0; L = cReader_ll(1, 1000000, ' '); R = cReader_ll(L, 1000000, '\n'); cReader_eof(); ps =Prime_L(2*R, p); for(i=(0);i<(ps);i++){ if(L <= p[i] && p[i] <= R){ res++; } if(2*L+1 <= p[i] && p[i] <= 2*R-1){ res++; } } wt_L(res); wt_L('\n'); return 0; } // cLay version 20210819-1 [beta] // --- original code --- // int ps, p[2d6]; // { // ll L, R, res = 0; // L = cReader_ll(1, 1d6, ' '); // R = cReader_ll(L, 1d6, '\n'); // cReader_eof(); // // ps = Prime(2*R, p); // rep(i,ps){ // if(L <= p[i] <= R) res++; // if(2*L+1 <= p[i] <= 2*R-1) res++; // } // wt(res); // }