stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int Q;

int lr[100000][2];

int plike[100001];

int p[100001];



int main(){

  cin >> Q;

  for(int i=0;i<Q;i++){

    cin >> lr[i][0] >> lr[i][1];

  }

  for(int i=0;i<100001;i++){

    p[i] = -1;

    plike[i] = 0;

  }

  for(int i=2;i<100001;i++){

    if(p[i] != -1) continue;

    p[i] = i;

    for(int j=i*2;j<100001;j+=i) p[j] = i;

  }

  for(int i=3;i<100001;i++){

    if(i%2 == 0){

      plike[i] = plike[i-1];

      continue;

    }

    if(p[i] != i){

      plike[i] = plike[i-1];

      continue;

    }

    if(p[(i+1)/2] != (i+1)/2){

      plike[i] = plike[i-1];

      continue;

    }

    plike[i] = plike[i-1] + 1;

  }

  for(int i=0;i<Q;i++){

    cout << plike[lr[i][1]] - plike[lr[i][0]-1] << endl;

  }

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



int p[100001];

ll Q;

ll l[100001];

ll r[100001];

int ans[100001];



int main(){

    ll Q;

    cin >> Q;

    ll N = 100000;

    for(int i=0;i<Q;i++) cin >> l[i] >> r[i];

    for(int i=1;i<=N;i++) p[i] = 1;

    for(int i=2;i*i<=N;i++){

        if(p[i] != 1) continue;

        for(int j=2;i*j<=N;j++) p[i*j]++;

    }

    p[1] = 0;

    for(int i=0;i<=N;i++){

        if(i%2 == 0){

            ans[i] = 0;

            continue;

        }

        if(p[i] == 1 && p[(i+1)/2] == 1) ans[i] = 1;

        else ans[i] = 0;

    }

    for(int i=2;i<=N;i++) ans[i] += ans[i-1];

    for(int i=0;i<Q;i++){

        cout << ans[r[i]] - ans[l[i]-1] << endl;

    }

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



#define rep(i, n) for (int i = 0; i < (n); i++)

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)

#define all(a) (a).begin(), (a).end()

#define all2(a, b) (a).begin(), (a).begin() + (b)

#define debug(vari) cerr << #vari << " = " << (vari) << endl;



int main()

{

    int MAX = 100100;

    vector<int> prime(MAX, 1);

    prime[0] = 0, prime[1] = 0;

    for (int i = 2; i < MAX; i++)

    {

        if (!prime[i])

            continue;

        for (int j = i * 2; j < MAX; j += i)

        {

            prime[j] = 0;

        }

    }



    vector<int> a(MAX, 0);

    for (int i = 0; i < MAX; i++)

    {

        if (i % 2 == 0)

            continue;

        if (prime[i] && prime[(i + 1) / 2])

            a[i] = 1;

    }



    vector<int> cum(MAX + 1, 0);

    for (int i = 0; i < MAX; i++)

    {

        cum[i + 1] = cum[i] + a[i];

    }



    int Q;

    cin >> Q;

    for (int q = 0; q < Q; q++)

    {

        int l, r;

        cin >> l >> r;

        r++;

        cout << cum[r] - cum[l] << endl;

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;



#define rep(i, n) for (int i = 0; i < (n); i++)

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)

#define all(a) (a).begin(), (a).end()

#define all2(a, b) (a).begin(), (a).begin() + (b)

#define debug(vari) cerr << #vari << " = " << (vari) << endl;



const int INF = 1001001001;



int ck(int a)

{

    if (a == 1)

    {

        return 0;

    }

    for (int i = 2; i * i <= a; i++)

    {

        if (a % i == 0)

        {

            return 0;

        }

    }

    return 1;

}



int main()

{

    int q;

    cin >> q;



    vector<int> l(q), r(q);

    rep(i, q) cin >> l[i] >> r[i];

    int r_max = -INF;

    rep(i, q) r_max = max(r_max, r[i]);



    vector<int> tmp(100000 + 10, 0), s(100000 + 10, 0);

    rep(num, r_max + 1)

    {

        if (num % 2 == 0)

            continue;

        if (ck(num) && ck((num + 1) / 2))

        {

            tmp[num]++;

        }

    }

    // rep(i, tmp.size())

    // {

    //     if (0 <= i && i <= r_max)

    //     {

    //         cout << tmp[i] << ' ';

    //     }

    // }

    // cout << endl;



    rep(i, s.size())

    {

        s[i + 1] = s[i] + tmp[i];

    }



    // rep(i, s.size())

    // {

    //     if (0 <= i && i <= r_max)

    //     {

    //         cout << s[i] << ' ';

    //     }

    // }

    // cout << endl;



    rep(i, q)

    {

        cout << s[r[i] + 1] - s[l[i]] << endl;

    }



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int p[100009],f[100009];

main()

{

    p[1]=1;



    for (int i=2; i<=100000; i++)

    {

        for (int j=2*i; j<=100000; j+=i)

            p[j]=1;

    }

    p[2]=0;

    for (int i=1; i<=100000; i++)//构造前缀和

    {

        if(p[i]==0 && p[(i+1)/2]==0 && i!=2)//如果该数满足要求，前缀和加1；否则不变

            {

                f[i]=f[i-1]+1;

            }

        else f[i]=f[i-1];

    }

    int q;

    cin>>q;

    while(q--)

    {

        int l,r;

        cin>>l>>r;

        cout<<f[r]-f[l-1]<<endl;//对于每组询问，直接输出f[r]-f[l-1]

    }

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

double pi = acos(-1);

int a[100005];

int sum[100005];

void A() {

  for (int i = 2; i*i < 100001; i++) {

    if (a[i] == 0)

      for (int j = i*i; j < 100001; j += i)

        a[j] = 1;

  }

  for (int i = 2; i < 100001; i++) {

    sum[i] += sum[i-1];

    if (!a[i] && !a[(i+1)/2] && (i+1) % 2 == 0) sum[i]++; 

  }

}

int main() {

  A();

  int n;

  scanf("%d", &n);

  while (n--) {

    int l, r;

    scanf("%d%d", &l, &r);

    printf("%d\n", sum[r]-sum[l-1]);

  }

  return 0;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n[N], m[N];

int main()

{

	int i, j, num = 0, find[N];

	n[1] = 1;

	for (i = 2; i <= 100000; i++)

	{

		for (j = 2 * i; j <= 100000; j += i)

			n[j] = 1;

	}

	n[2] = 0;

	for (i = 1; i <= 100000; i++)

	{

		if (n[i] == 0 && n[(i + 1) / 2] == 0)

			m[i] = m[i - 1] + 1;

		else

			m[i] = m[i - 1];

	}

	int a, b, c;

	cin >> a;

	for (i = 1; i <= a; i++)

	{

		cin >> b >> c;

		find[i] = m[c] - m[b-1];

	}

	for (i = 1; i <= a; i++)

		cout << find[i] << endl;

	return 0;

}






// Optimized solution to the same problem (faster):
#include<iostream>

#include<iomanip>

#include<cstring>

#include<cstdio>

#include<cmath> 

using namespace std;

long long n[50050],f[100050],zs,a,lefts,rights;

//n[]为辅助空间，里面处理完全是质数；f[]用来前缀和，zs代表质数个数（欧拉线筛需要）

bool b[100050];

//标准的质数表

int main()

{

	b[0]=1,b[1]=1;//初始值

	for(int s=2;s<=100005;s++)//欧拉线筛

	{

		if(!b[s])//一个质数

		{

			n[zs++]=s;

		}

		for(int v=0;v<zs;v++)//处理

		{

			if(s*n[v]>100005)break;//超过了所求的质数范围

			b[n[v]*s]=true;//筛质数

			if(s%n[v]==0)break;//压成到O(n)的关键

		}

	}

	cin>>a;

	for(int s=2;s<=100005;s++)//前缀和

	{

		if(s%2==1&&b[s]==0&&b[(s+1)/2]==0)

		f[s]=1;

		f[s]+=f[s-1];

	}

	while(a--)//输入

	{

		cin>>lefts>>rights;

		cout<<f[rights]-f[lefts-1]<<endl;//前缀和的大法

	}

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#include<iostream>

#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

typedef unsigned long long ull;

#define ll long long

#define INF  0x7fffffff

#define M 200000

#define N 100000

#define legal(x) ((1<=(x))&&((x)<=M))

const ll  mod=1e9 + 7;

ll n,k,ans[M],p[M],t,l,r,f[M],sum;

int main(void){

	p[1] = 1;

	for(ll i = 2;i <= N;i++){

		if(!p[i])

		ans[++sum] = i;

		for(ll j = 1;j <=sum&&i*ans[j]<=N;j++){

			p[ans[j]*i] = 1;

			if(i %ans[j]==0)

			break;

		}

	}

	p[2] = 0;

	for(ll i = 1;i <= N;i++){

		if(p[i]==0&&p[(i+1)/2]==0&&i!=2){

			f[i] =f[i-1]+1;

		}

		else

		f[i] = f[i-1];

	}

	cin>>t;

	while(t--){

		cin>>l>>r;

		cout<<f[r] -f[l-1]<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<iomanip>

#include<cstring>

#include<cstdio>

#include<cmath> 

using namespace std;

long long n[50050],f[100050],zs,a,lefts,rights;

//n[]为辅助空间，里面处理完全是质数；f[]用来前缀和，zs代表质数个数（欧拉线筛需要）

bool b[100050];

//标准的质数表

int main()

{

	b[0]=1,b[1]=1;//初始值

	for(int s=2;s<=100005;s++)//欧拉线筛

	{

		if(!b[s])//一个质数

		{

			n[zs++]=s;

		}

		for(int v=0;v<zs;v++)//处理

		{

			if(s*n[v]>100005)break;//超过了所求的质数范围

			b[n[v]*s]=true;//筛质数

			if(s%n[v]==0)break;//压成到O(n)的关键

		}

	}

	cin>>a;

	for(int s=2;s<=100005;s++)//前缀和

	{

		if(s%2==1&&b[s]==0&&b[(s+1)/2]==0)

		f[s]=1;

		f[s]+=f[s-1];

	}

	while(a--)//输入

	{

		cin>>lefts>>rights;

		cout<<f[rights]-f[lefts-1]<<endl;//前缀和的大法

	}

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



int main() {

    int MAX = 101010;

    vector<int> is_prime(MAX, 1);

    is_prime[0] = 0;

    is_prime[1] = 0;



    for(int i=2; i<MAX; ++i){

        if(!is_prime[i]){

            continue;

        }

        for(int j=i*2; j<MAX; j+=i){

            is_prime[j] = 0;

        }

    }



    vector<int> a(MAX, 0);

    for(int i=0; i<MAX; ++i){

        if(i%2==0){

            continue;

        }

        if(is_prime[i] && is_prime[(i+1)/2]){

            a[i] = 1;

        }

    }



    vector<int> s(MAX+1, 0);

    for(int i=0; i<MAX; ++i){

        s[i+1] = s[i] + a[i];

    }



    int q;

    cin >> q;



    for(int i=0; i<q; i++){

        int l, r;

        cin >> l >> r;

        r++;



        cout << s[r] - s[l] << endl;

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i, n) for(int i=0; i<(n); ++i)

#define chmin(x,y) x = min(x,y)

#define chmax(x,y) x = max(x,y)

using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;

typedef pair<int, int> P;

const int inf = INT_MAX;

const ll INF = 1LL << 60;

const ll mod = 1e9+7;

const int dx[4] = {-1, 0, 1, 0};

const int dy[4] = {0, -1, 0, 1};



// 084d



int main(){

    int q;

    cin >> q;

    int l[100005], r[100005];

    rep(i, q) cin >> l[i] >> r[i];



    vector<int> c(100005, 1);

    c[0] = 0, c[1] = 0;

    for(int i=2; i<100005; i++){

        if (!c[i]) continue;

        for(int j=i*2; j<100005; j+=i) c[j] = 0;

    }

    vector<int> judge(100005, 1);

    rep(i, 100004){

        if (c[i]==1 and c[(i+1)/2]==1 and i%2==1){

            judge[i] = 1;

        }else judge[i] = 0;

    }

    rep(i, 100004) judge[i+1] = judge[i] + judge[i+1];

    rep(i, q){ 

        int ll = l[i], rr = r[i];

        cout << judge[rr] - judge[ll-1] << endl;

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



const int PRIME_MAX = 1e5+100;



int main(){

    using namespace std;

    int Q; cin >> Q;

    vector<int> l(Q), r(Q);

    vector<int> n_like(PRIME_MAX, 0);

    for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];



    vector<bool> is_prime(PRIME_MAX, true);

    is_prime[0] = is_prime[1] = false;

    for (int i = 4; i < PRIME_MAX; i+=2) is_prime[i] = false;

    for (int i = 3; i < PRIME_MAX; i+=2)

    {

        if(!is_prime[i]) continue;

        for (int j = i*2; j < PRIME_MAX; j+=i) is_prime[j] = false;  

    }

    

    for (int i = 1; i < PRIME_MAX; i++)

    {

        if(i%2==1 && is_prime[i] && is_prime[(i+1)/2]) n_like[i] = n_like[i-1] + 1;

        else n_like[i] = n_like[i-1];

    }

    

    for (int i = 0; i < Q; i++)

    {

        cout << n_like[r[i]] - n_like[l[i]-1] << endl;

    }

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



/*

template<size_t max_N>

struct Prime{

    bool is_prime[max_N];

    constexpr Prime() : is_prime() {

        for(int i = 0; i < max_N; i++) is_prime[i] = true;

        is_prime[0] = is_prime[1] = false;

        for (int i = 0; i < max_N; i++)

        {

            if(!is_prime[i]) continue;

            for (int j = i*i; j < max_N; j+=i) is_prime[j] = false;

        }

        

    }

};

*/



template<size_t max_N, size_t prime_size>

struct Prime{

    bool sieve[max_N];

    int_fast64_t prime[prime_size];

    size_t counter = 0;

    constexpr Prime() : sieve(), prime() {

        for(int_fast64_t i = 0; i < max_N; ++i)

            sieve[i] = true;

        sieve[0] = sieve[1] = false;

        for(int_fast64_t i = 2; i < max_N; ++i){

            if(sieve[i]){

                prime[counter] = i;

                ++counter;

                if(counter > prime_size)break;

            }

            for(int_fast64_t j = i * i; j < max_N; j += i)

                sieve[j] = false;

        }

    }

};

int main(){

    using namespace std;

    const int PRIME_MAX = 1e5+100;

    int Q; cin >> Q;

    vector<int> l(Q), r(Q);

    vector<int> n_like(PRIME_MAX, 0);

    for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];

    constexpr auto p = Prime<PRIME_MAX, 10000>();

    for (int i = 1; i < PRIME_MAX; i++)

    {

        if(i%2==1 && p.sieve[i] && p.sieve[(i+1)/2]) n_like[i] = n_like[i-1] + 1;

        else n_like[i] = n_like[i-1];

    }

    

    for (int i = 0; i < Q; i++)

    {

        cout << n_like[r[i]] - n_like[l[i]-1] << endl;

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#define MAX_N 100001



using namespace std;



vector<bool> IsPrime(MAX_N, true);



// エラトステネスの篩

void get_primes() {

    IsPrime[0] = false;

    IsPrime[1] = false;



    for (int i = 2; i*i <= MAX_N; i++) {

        if (IsPrime[i]) {

            for (int j = i*i; j <= MAX_N; j += i) {

                IsPrime[j]= false;

            }

        }

    }

}



int main() {

    int Q, l, r;

    vector<int> cnt(MAX_N, 0);



    get_primes();



    for (int i = 3; i <= MAX_N; i += 2) {

        if (IsPrime[i] && IsPrime[(i+1)/2]) { cnt[i]++; }

    }

    // 2017 に似てる数の累積和をとっている

    for (int i = 1; i <= MAX_N; i++) {

        cnt[i] += cnt[i-1];

    }



    cin >> Q;



    while (Q--) {

        cin >> l >> r;

        cout << cnt[r] - cnt[l-1] << endl;

    }



    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#define MAX_N 100001



bool IsPrime[MAX_N];



void get_primes() {

    IsPrime[0] = false;

    IsPrime[1] = false;



    for (int i = 2; i*i <= MAX_N; i++) {

        if (IsPrime[i]) {

            for (int j = i*i; j <= MAX_N; j += i) {

                IsPrime[j]= false;

            }

        }

    }

}



int main() {

    int Q, l, r;

    int cnt[MAX_N] = {0};



    memset(IsPrime, 1, sizeof(IsPrime));

    get_primes();



    for (int i = 3; i <= MAX_N; i += 2) {

        if (IsPrime[i] && IsPrime[(i+1)/2]) { cnt[i]++; }

    }

    // 2017 に似てる数の累積和をとっている

    for (int i = 1; i <= MAX_N; i++) {

        cnt[i] += cnt[i-1];

    }



    scanf("%d", &Q);



    while (Q--) {

        scanf("%d %d", &l, &r);

        printf("%d\n", cnt[r] - cnt[l-1]);

    }



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int dp[100009], total[100009];

int store[100009], mark[100009], nPrime, isPrime[100009];



///seieve

void seive(int n)

{

    int i,j, lim = sqrt(n*1.0) +2;



    mark[1] = 1;

    for(i = 4; i<=n; i+=2) mark[i] = 1;



    store[nPrime++] = 2;



    isPrime[2] = 1;



    for(i=3; i<=n; i+=2)

    {

        if(!mark[i])

        {

            store[nPrime++] = i;

            isPrime[i] = 1;



            if(i<=lim)

            {

                for(j=i*i; j<=n; j+=i*2)

                {

                    mark[j]=1;

                }

            }

        }

    }





}



int f(int n) /// is like 2017

{

    if(dp[n]!=-1) return dp[n];

    if(n%2==0) return dp[n] = 0;

    if(isPrime[n]==1 && isPrime[ (n+1)/2 ]==1) return dp[n] = 1;

    else return dp[n] = 0;

}



void cnt(int N)

{

    for(int i=0; i<=N; i++) f(i);

    total[1] = 0;

    for(int i=2; i<=N; i++)

    {

        total[i] = total[i-1]+dp[i];

    }

}



int main()

{

    int q;

    int l, r;

    int ans = 0;



    seive(100002);

    memset(dp,-1,sizeof(dp));

    cnt(100002);



    //for(int i=0; i<nPrime; i++) cout<<store[i]<<" ";

    //for(int i=0; i<100000; i++) if(dp[i]) cout<<i<<" "<<total[i]<<" "<<endl;



    cin>>q;

    while(q--)

    {

        cin>>l>>r;

        if(l==1) ans = total[r];

        else ans = total[r] - total[l-2];

        cout<<ans<<endl;

    }



    //main();





    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>





using namespace std;



typedef long long ll;



const int MAXN = 100 * 1000 + 123;









bool inp[MAXN];

int ps[MAXN];



void gh() {

	inp[0] = inp[1] = true;

	for (int i = 2; i < MAXN; i++)

		if (!inp[i])

			for (ll j = (ll)i * i; j < MAXN; j += i)

				inp[j] = true;

}





int main() {

	gh();

	for (int i = 1; i < MAXN; i++) {

		ps[i] = ps[i - 1];

		if (!inp[i - 1] && !inp[i >> 1])

			ps[i]++;

	}

	int q, l, r;

	cin >> q;

	while (q--) {

		cin >> l >> r;

		cout << ps[r + 1] - ps[l] << '\n';

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/**

*　　　　　　　　┏┓　　 　┏┓

* 　　　　　　　┏┛┗━━━━━━━┛┗━━━┓

* 　　　　　　　┃　　　　　　　┃ 　

* 　　　　　　　┃　　　━　　 　┃

* 　　　　　　　┃　＞　　　＜　┃

* 　　　　　　　┃　　　　　　　┃

* 　　　　　　　┃...　⌒　... 　┃

* 　　　　　　　┃　　　　　　　┃

* 　　　　　　　┗━┓　　　┏━┛

* 　　　　　　　　　┃　　　┃　　　　　　　　　　

* 　　　　　　　　　┃　　　┃

* 　　　　　　　　　┃　　　┃　　　　　　　　　　　

* 　　　　　　　　　┃　　　┃  　　　　　　

* 　　　　　　　　　┃　　　┃

* 　　　　　　　　　┃　　　┃　　　　　　　　　　　

* 　　　　　　　　　┃　　　┗━━━┓

* 　　　　　　　　　┃　　　　　　　┣┓

* 　　　　　　　　　┃　　　　　　　┏┛

* 　　　　　　　　　┗┓┓┏━┳┓┏┛

* 　　　　　　　　　　┃┫┫　┃┫┫

* 　　　　　　　　　　┗┻┛　┗┻┛

*/

#include<iostream>  

#include<cstdio>  

#include<fstream>  

#include<iomanip>

#include<algorithm>  

#include<cmath>  

#include<deque>  

#include<vector>

#include<bitset>

#include<queue>  

#include<string>  

#include<cstring>  

#include<map>  

#include<stack>  

#include<set>

#include<cassert>

#include<functional>



#define pii pair<int, int>

#define mod 1000000007

#define mp make_pair

#define pi acos(-1)

#define eps 0.000000001

#define mst(a,i) memset(a,i,sizeof(a))

#define all(n) n.begin(),n.end()

#define lson(x) ((x<<1))  

#define rson(x) ((x<<1)|1) 

#define inf 0x3f3f3f3f

typedef long long ll;

typedef unsigned long long ull;

using namespace std;

const int maxn = 1e5 + 5;



vector<int>prime;

int isprime[maxn];



void getprimelist(int t)

{

	mst(isprime, 1);

	isprime[1] = 0;

	for (int i = 2; i <= t; ++i)

	{

		if (isprime[i])prime.push_back(i);

		for (int j = 0; j < prime.size() && prime[j] * i <= t; ++j)

		{

			isprime[prime[j] * i] = 0;

			if (i%prime[j] == 0)break;

		}

	}

}

int ok[maxn];

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0); cout.tie(0);

#ifdef DEBUG

	freopen("old_data.json", "r", stdin);

	freopen("1.out", "w", stdout);

#endif // DEBUG clang++ checker.cpp --target=i686-pc-mingw32 -o checker.exe

	int n;

	getprimelist(100000);

	for (int i = 1; i <= 100000; ++i) {

		if (isprime[i] && isprime[(i + 1) / 2])ok[i] = 1;

	}

	for (int i = 1; i <= 100000; ++i)ok[i] += ok[i - 1];

	cin >> n;

	int l, r;

	for (int i = 1; i <= n; ++i) {

		cin >> l >> r;

		cout << ok[r] - ok[l - 1] << endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>





using namespace std;



typedef long long ll;



const int MAXN = 100 * 1000 + 123;









bool inp[MAXN];

int ps[MAXN];



void gh() {

	inp[0] = inp[1] = true;

	for (int i = 2; i < MAXN; i++)

		if (!inp[i])

			for (ll j = (ll)i * i; j < MAXN; j += i)

				inp[j] = true;

}





int main() {

	gh();

	for (int i = 1; i < MAXN; i++) {

		ps[i] = ps[i - 1];

		if (!inp[i - 1] && !inp[i >> 1])

			ps[i]++;

	}

	int q, l, r;

	cin >> q;

	while (q--) {

		cin >> l >> r;

		cout << ps[r + 1] - ps[l] << '\n';

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define int long long



const int N = 1e5 + 10;

int q, mark[N], psum[N];



int32_t main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	

	mark[1] = 1;

	for (int i = 2; i < N; i++)

		if (!mark[i])

			for (int j = 2 * i; j < N; j += i)

				mark[j] = 1;

				

	for (int i = 1; i < N; i += 2)

		psum[i] = (!mark[i] && !mark[(i + 1) / 2]);

	for (int i = 1; i < N; i++)

		psum[i] += psum[i - 1];

	

	cin >> q;

	while (q--) {

		int l, r;

		cin >> l >> r;

		cout << psum[r] - psum[l - 1] << '\n';

	}

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>





using namespace std;



typedef long long ll;



const int MAXN = 100 * 1000 + 123;









bool inp[MAXN];

int ps[MAXN];



void gh() {

	inp[0] = inp[1] = true;

	for (int i = 2; i < MAXN; i++)

		if (!inp[i])

			for (ll j = (ll)i * i; j < MAXN; j += i)

				inp[j] = true;

}





int main() {

	gh();

	for (int i = 1; i < MAXN; i++) {

		ps[i] = ps[i - 1];

		if (!inp[i - 1] && !inp[i >> 1])

			ps[i]++;

	}

	int q, l, r;

	cin >> q;

	while (q--) {

		cin >> l >> r;

		cout << ps[r + 1] - ps[l] << '\n';

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



const int MAX_R = 1e5 + 3;

bool p[MAX_R+5];

int r[MAX_R+5];



void init() {

    for(int i = 0; i <= MAX_R + 1; ++i) p[i] = true;

    p[0] = p[1] = false;

    int i = 2;

    while(i <= MAX_R) {

        for(int j = 2; j*i <= MAX_R; ++j) p[j*i] = false;

        while(p[++i] == false);

    }

    for(int i = 0; i <= MAX_R; ++i) {

        r[i] = r[i-1];

        if(i > 0 && p[i] && p[(i+1)/2]) ++r[i];

    }

}



int main()

{

    int Q;

    cin >> Q;

    init();

    int c[Q+2];

    for(int i = 0; i < Q; ++i) {

        int L, R;

        cin >> L >> R;

        c[i] = r[R] - r[L-1];

    }

    for(int i = 0; i < Q; ++i) cout << c[i] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

bool f[100001];

int  c[100002];

int N, L, R;

int main()

{

    for(int i = 2; i <= 100000; ++i) 

        if(!f[i])

            for(int j = i + i; j <= 100000; j += i)

                f[j] = true;

    

    for(int i = 3; i <= 100000; i += 2)

        if(!f[i] && !f[(i+1)/2]) c[i]++;

    

    for(int i = 3; i <= 100000; ++i) c[i] += c[i-1];

    scanf("%d", &N);

    while(N--) {

        scanf("%d %d", &L,&R);

        printf("%d\n", c[R] - c[L-1]);

    }



    return 0;

}

// Fastest known solution for this problem: