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

using namespace std;



#define N 100000



int main(void){

    ios::sync_with_stdio(false);

    vector<bool> prime(N+1,true);

    prime[0]=prime[1]=false;

    for (size_t i = 0; i <= sqrt(N); i++)

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    vector<int> likeCnt(N);

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

    {

        likeCnt[i]=likeCnt[i-1];

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

        {

            likeCnt[i]++;

        }

    }

    /**************************************/

    int q;

    cin >> q;

    int l,r;

    for (size_t i = 0; i < q; i++)

    {

        cin >> l >> r;

        cout << likeCnt[r] - likeCnt[l-1] << "\n";

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

    vector<bool> prime(N+1,true);

    prime[0]=prime[1]=false;

    for (size_t i = 2; i <= sqrt(N); i++)

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    int likeCnt[N+1];

    for (size_t i = 3; i <= N; i+=2)

    {

        likeCnt[i]=likeCnt[i-1];

        if (i%2==1&&prime[i]&&prime[(i+1)/2]) likeCnt[i]++;

        likeCnt[i+1]=likeCnt[i];

    }

    /**************************************/

    int q;

    scanf("%d", &q);

    int l,r;

    for (size_t i = 0; i < q; i++)

    {

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

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

    ios::sync_with_stdio(false);

    vector<bool> prime(N+1,true);

    prime[0]=prime[1]=false;

    for (size_t i = 0; i*i <= N; i++)

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    vector<int> likeCnt(N);

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

    {

        likeCnt[i]=likeCnt[i-1];

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

        {

            likeCnt[i]++;

        }

    }

    /**************************************/

    int q;

    cin >> q;

    int l,r;

    for (size_t i = 0; i < q; i++)

    {

        cin >> l >> r;

        cout << likeCnt[r] - likeCnt[l-1] << "\n";

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

    vector<bool> prime(N+1,true);

    prime[0]=prime[1]=false;

    for (size_t i = 2; i <= sqrt(N); i++)

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    int likeCnt[N+1];

    for (size_t i = 3; i <= N; i+=2)

    {

        likeCnt[i]=likeCnt[i-1];

        if (i%2==1&&prime[i]&&prime[(i+1)/2]) likeCnt[i]++;

        likeCnt[i+1]=likeCnt[i];

    }

    /**************************************/

    int q;

    scanf("%d", &q);

    int l,r;

    for (size_t i = 0; i < q; i++)

    {

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

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

    ios::sync_with_stdio(false);

    vector<bool> prime(N+1,true);

    prime[0]=prime[1]=false;

    for (size_t i = 2; i*i <= N; i++)

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    vector<int> likeCnt(N);

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

    {

        likeCnt[i]=likeCnt[i-1]+(i%2==1&&prime[i]&&prime[(i+1)/2]);

    }

    /**************************************/

    int q;

    cin >> q;

    int l,r;

    for (size_t i = 0; i < q; i++)

    {

        cin >> l >> r;

        cout << likeCnt[r] - likeCnt[l-1] << "\n";

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

    vector<bool> prime(N+1,true);

    prime[0]=prime[1]=false;

    for (size_t i = 2; i <= sqrt(N); i++)

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    int likeCnt[N+1];

    for (size_t i = 3; i <= N; i+=2)

    {

        likeCnt[i]=likeCnt[i-1];

        if (i%2==1&&prime[i]&&prime[(i+1)/2]) likeCnt[i]++;

        likeCnt[i+1]=likeCnt[i];

    }

    /**************************************/

    int q;

    scanf("%d", &q);

    int l,r;

    for (size_t i = 0; i < q; i++)

    {

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

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

    }

    return 0;

}

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

using namespace std;



const int Nmax = 100001;

int Q;

bool isPrime[Nmax];

int cnt[Nmax];



int main() {

	fill(isPrime, isPrime + Nmax, 1);

	isPrime[1] = false;

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

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

			isPrime[i*j] = false;

		}

	}



	int buf = 0;

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

		if (isPrime[i]) {

			if (isPrime[(i + 1) / 2]) {

				buf++;

			}

		}

		cnt[i] = buf;

	}



	cin >> Q;

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

		int l, r;

		cin >> l >> r;

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

	}



	return 0;

}

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

#define ll long long

using namespace std;



int main(){

    int N = 100000;

    vector<bool> is2017(N+1, true);

    is2017[0] = false;

    is2017[1] = false;

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

        if(!is2017[i]) continue;

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

            is2017[i*j] = false;

        }

    }



    for(int i=N; i>=0; i--){

        if(!(is2017[i] && is2017[(i+2)/2])) is2017[i] = false;

    }

    is2017[2] = false;



    vector<int> cnt(N+1,0);

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

        if(is2017[i]) cnt[i]++;

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

    }



    int Q; cin >> Q;

    while(Q > 0){

        int l, r;  cin >> l >> r;

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

        Q--;

    }

}


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



using namespace std;

using ll = long long;

using pii = pair<int, int>;



vector<int> prime;

bool is_prime[1000010];

int sieve(int n) {

  fill(is_prime + 2, is_prime + 1000010, true);

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

    if (is_prime[i]) {

      prime.emplace_back(i);

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

    }

  }

  return prime.size();

}



int main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  cout << fixed << setprecision(10);

  

  int Q;

  cin >> Q;

  sieve(100000);

  int cum[100010] = {};

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

    cum[i] = (is_prime[i] && is_prime[(i + 1) / 2]) + cum[i - 1];

  }

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

    int l, r;

    cin >> l >> r;

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

  }



  return 0;

}

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

#define int long long

#define uint unsigned int

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

#define REPR(i, n) for (int i = (n); i >= 0; --i)

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

#define FORR(i, a, b) for (int i = (a); i >= (b); --i)

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

#define ALLR(a) (a).rbegin(), (a).rend()

#define SZ(a) ((int)(a).size())

#define PB(a) push_back(a)

#define EMP emplace

#define EMPB(...) emplace_back(__VA_ARGS__)

#define MP(a, b) make_pair(a, b)

#define MT(...) make_tuple(__VA_ARGS__)

#define Bit(n) (1LL << (n))

using namespace std;

using pii = pair<int, int>;

template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD = 1000000007;

const int INF = 1LL << 30;

const double EPS = 1e-10;



const int MAX_N = 1000010;

vector<int> prime;

bool is_prime[MAX_N];



int sieve(int n) {

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

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

    if (is_prime[i]) {

      prime.push_back(i);

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

    }

  }

  return prime.size();

}



int Q;

int l[100010], r[100010];

int cum[100010];



signed main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  cout << fixed << setprecision(10);

  

  sieve(100010);

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

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

  }

  REP(i, 100009) cum[i+1] += cum[i];

  cin >> Q;

  REP(i, Q) {

    cin >> l[i] >> r[i];

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

  }



  return 0;

}

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

using P = pair<int,int>;



/* 大文字を小文字に変換 */

char tolower(char c) {return (c + 0x20);}

/* 小文字を大文字に変換 */

char toupr(char c) {return (c - 0x20);}



// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';



/*

string s = "abcdefg"

s.substr(4) "efg"

s.substr(0,3) "abc"

s.substr(2,4) "cdef"



// イテレータ要素のインデックス

distance(A.begin(), itr);

*/



bool f[100005];

int c[100005];



void init(){

    rep(i,100005){

        f[i] = true;

        c[i] = 0;

    }

}



int main()

{

    init();

    f[0] = f[1] = false;

    // エラトステネスの篩にかけて素数のみをtrueとする

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

        if(f[i] == true){

            int j = i + i;

            while(j<=100000){

                f[j] = false;

                j = j + i;

            }

        }

    }

    // 2017に似た数をカウントする

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

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

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

        // cout << c[i] << endl;

    }



    // 入力値を読み込み

    

    int Q; cin >> Q;

    rep(_, Q){

        int l, r; cin >> l >> r;

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

    }

    

}

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

using P = pair<ll, ll>;



/* 大文字を小文字に変換 */

char tolower(char c) {return (c + 0x20);}

/* 小文字を大文字に変換 */

char toupr(char c) {return (c - 0x20);}



// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';



/*

string s = "abcdefg"

s.substr(4) "efg"

s.substr(0,3) "abc"

s.substr(2,4) "cdef"



// イテレータ要素のインデックス

distance(A.begin(), itr);

*/





int main()

{

    int max_n = 100000;

    bool isprime[max_n+1];

    rep(i,max_n+1) isprime[i] = true;



    isprime[0] = isprime[1] = false;

    for(int i=4; i<=max_n; i+=2){

        isprime[i] = false;

    }



    // エラトステネスの篩

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

        if(isprime[i]){

            int j=i+i;

            while(j<=max_n){

                isprime[j] = false;

                j += i;

            }

        }

    }



    int prime_num[max_n+1];

    prime_num[0] = prime_num[1] = prime_num[2] = 0;

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

        if(i%2 == 1){

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

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

        }

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

    }



    int q; cin >> q;

    rep(_,q){

        int l, r; cin >> l >> r;

        //cout << prime_num[l] << endl;

        //cout << prime_num[r] << endl;

        cout << (prime_num[r] - prime_num[l-1]) << endl;

    }

}

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



vector<int> prime_vector(int n) {

    vector<int> p;

    vector<char> q(n);

    int m = (int)sqrt(n - 1);



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

        if (q[i] != 0) continue;

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

            q[j] = 1;

        }

    }

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

        if (q[i] == 0) p.push_back(i);

    }

    return p;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    auto v = prime_vector(100000);

    vector<int> a(100002);

    for (int i = 0; i < v.size(); i++) {

        a[v[i]] = 1;

    }

    for (int i = 100000; i >= 0; i--) {

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

    }

    a[2] = 0;

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

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

    }



    int q;

    cin >> q;



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

        int l, r;

        cin >> l >> r;



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

    }



    return 0;

}

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



vector<int> prime_vector(int n) {

    int m = (int)sqrt(n - 1);



    vector<bool> q(n);

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

        if (q[i]) continue;

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

            q[j] = true;

        }

    }



    vector<int> p; p.reserve(n / log(n * 0.329));

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

        if (!q[i]) p.push_back(i);

    }

    return p;

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    constexpr int N = 100000;



    auto v = prime_vector(N + 1);



    vector<int> a(N + 1);

    for (auto& i : v) {

        a[i] = 1;

    }

    for (int i = N; i >= 0; i--) {

        if (a[(i + 1) / 2] == 0) a[i] = 0;

    }

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

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

    }



    int q;

    cin >> q;



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

        int l, r;

        cin >> l >> r;



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

    }



    return 0;

}

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

using namespace std;

int main(){

  int q;

  cin >> q;

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

  vector<bool> p(100010,true);

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

    cin >> l[i] >> r[i];

  }

  p[0]=false;

  p[1]=false;

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

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

      p[i*j]=false;

    }

  }

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

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

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

    }

    else{

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

    }

  }

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

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

  }

}

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

using namespace std;

typedef long long ll;

typedef long double ld;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INF=1LL<<60;

const int inf=1<<30;

const int mod=1e9+7;

const int MOD=998244353;

int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int q;cin >> q;

    vector<bool> p(100001,true);

    p[0]=false;

    p[1]=false;

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

        if(p[i]){

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

                p[i*j]=false;

            }

        }

    }

    vector<int> sum(100001);

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

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

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

        }

        else{

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

        }

    }

    while(q--){

        int l,r;cin >> l >> r;

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

    }

}

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

using namespace std;

long long s,n,i,j,a,b,o[1000000]= {1,1},k[1000009];

int main() {

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

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

			o[j]=1;

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

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

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

		}

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

	}

	cin>>n;

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

		cin>>a>>b;

		cout<<k[b]-k[a-1]<<endl;

	}

	return 0;

}

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

using namespace std;

char a[100000+1];//0表是

int L,r,c[100001];

void prime(){

	a[0]=a[1] = 1;

	int t=sqrt(100000);					

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

		if(a[i]==0) {

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

			     a[j] = 1;	

		}				

	}

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

    {

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

        {

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

        }

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

    }

}

int main(){

	prime(); 						 

	int q;//输入q组数据 

	cin>>q;							

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

		cin>>L>>r;

	    cout<<c[r]-c[L-1]<<endl;

	}	

	return 0;

} 

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

#include<algorithm>

#include<cstdlib>

#include<cstring>

#include<cstdio>

#include<cmath>

#include<iomanip>

#include<vector>

#include<queue>

#include<set>

#include<map>

using namespace std;

int n;

int p[100005],f[100005];

int main()

{

	p[1]=1;

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

    {

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

        p[j]=1;

    }

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

    {

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

		{

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

		}

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

    }

	scanf("%d",&n);

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

	{

		int x,y;

		scanf("%d%d",&x,&y);

		printf("%d\n",f[y]-f[x-1]);



	}

	return 0;

}

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

using namespace std;

char a[100000+1];//0表是

int L,r,c[100001];

void prime(){

	a[0]=a[1] = 1;

	int t=sqrt(100000);					

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

		if(a[i]==0) {

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

			     a[j] = 1;	

		}				

	}

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

    {

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

        {

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

        }

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

    }

}

int main(){

	prime(); 						 

	int q;//输入q组数据 

	cin>>q;							

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

		cin>>L>>r;

	    cout<<c[r]-c[L-1]<<endl;

	}	

	return 0;

} 

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

#include <cstring>



#define SIZE 100005



// 1为2017数

int numbers[SIZE];

int _2017[SIZE];



int main() {

	numbers[1] = 0;

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

		numbers[i] = 1;

	}



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

		if (numbers[i]) {

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

				numbers[j * i] = 0;

			}

		}

	}



	// 求2017数

	memcpy(_2017, numbers, sizeof numbers);

	_2017[2] = 0;

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

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

			_2017[i] = 0;

		}

	}



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

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

	}





	int question;

	std::cin >> question;

	while (question--) {

		int left, right;

		std::cin >> left >> right;



		std::cout << _2017[right] - _2017[left - 1] << std::endl;

	}



	return 0;

}


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

using namespace std;

char a[100000+1];//0表是

int L,r,c[100001];

void prime(){

	a[0]=a[1] = 1;

	int t=sqrt(100000);					

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

		if(a[i]==0) {

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

			     a[j] = 1;	

		}				

	}

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

    {

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

        {

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

        }

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

    }

}

int main(){

	prime(); 						 

	int q;//输入q组数据 

	cin>>q;							

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

		cin>>L>>r;

	    cout<<c[r]-c[L-1]<<endl;

	}	

	return 0;

} 

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

const int N = 1e5+50;

bool death[N];

int primelist[N], a[N];

using namespace std;

int main() {

    int t, m, n, tail = 0;   

    death[1] = 1;

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

    	if( !death[i] )

    		primelist[++tail] = i;

    	for(int j = 1; j <= tail; ++j) {

    		if(primelist[j]*i > N) break;

    		death[primelist[j]*i] = 1;

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

    	}	

    }

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

      if((i&1)&&(!death[i])&&(!death[(i+1)/2]))

             a[i] = 1;

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

        } 

    cin>>t;

    while(t--) {

      int sum = 0;

      cin>>m>>n;

      cout<<(a[n]-a[m-1])<<"\n";

    }  

    return 0;

} 

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

using namespace std;

char a[100000+1];//0表是

int L,r,c[100001];

void prime(){

	a[0]=a[1] = 1;

	int t=sqrt(100000);					

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

		if(a[i]==0) {

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

			     a[j] = 1;	

		}				

	}

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

    {

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

        {

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

        }

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

    }

}

int main(){

	prime(); 						 

	int q;//输入q组数据 

	cin>>q;							

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

		cin>>L>>r;

	    cout<<c[r]-c[L-1]<<endl;

	}	

	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 f[N],prime[N],n,ans[N],x=0,a,b,temp;

void Check(){

	f[1]=1;

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

			if(!f[i]) 

			prime[x++]=i;

	for(int j=0;j<x;j++){

	if(i*prime[j]>N) break;

	f[i*prime[j]]=1;

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

}

}

}

int main(){

	Check();

	ans[1]=0;

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

		if(!f[i]&&!f[(i+1)>>1]){

		ans[i]=temp+1;

		temp=ans[i];

	}

	else

	ans[i]=temp;

	}

		cin>>n;

		while(n--){

			cin>>a>>b;

			if(!f[a]&&!f[(a+1)>>1])

			cout<<(ans[b]-ans[a]+1)<<endl;

			else

			cout<<ans[b]-ans[a]<<endl;

		}

}

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

using namespace std;

char a[100000+1];//0表是

int L,r,c[100001];

void prime(){

	a[0]=a[1] = 1;

	int t=sqrt(100000);					

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

		if(a[i]==0) {

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

			     a[j] = 1;	

		}				

	}

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

    {

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

        {

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

        }

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

    }

}

int main(){

	prime(); 						 

	int q;//输入q组数据 

	cin>>q;							

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

		cin>>L>>r;

	    cout<<c[r]-c[L-1]<<endl;

	}	

	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 f[N],n,ans[N],x=0,a,b,temp;

void Check(){

	f[1]=1;

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

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

	f[j]=1;

}

int main(){

	Check();

	ans[1]=0;

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

		if(!f[i]&&!f[(i+1)>>1]){

		ans[i]=temp+1;

		temp=ans[i];

	}

	else

	ans[i]=temp;

	}

		cin>>n;

		while(n--){

			cin>>a>>b;

			if(!f[a]&&!f[(a+1)>>1])

			cout<<(ans[b]-ans[a]+1)<<endl;

			else

			cout<<ans[b]-ans[a]<<endl;

		}

}

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

using namespace std;

char a[100000+1];//0表是

int L,r,c[100001];

void prime(){

	a[0]=a[1] = 1;

	int t=sqrt(100000);					

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

		if(a[i]==0) {

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

			     a[j] = 1;	

		}				

	}

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

    {

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

        {

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

        }

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

    }

}

int main(){

	prime(); 						 

	int q;//输入q组数据 

	cin>>q;							

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

		cin>>L>>r;

	    cout<<c[r]-c[L-1]<<endl;

	}	

	return 0;

} 

// Fastest known solution for this problem: