stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.9502330412946947x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.2408098610415164x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.7376587805121242x):
#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;

		}

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.952471095277753x):
#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;

		}

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.2422337931526648x):
#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;

		}

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 2.128784934745136x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+5;

int m,li,ri;

int prime[maxn];

int dp[maxn];

void caculatePrime(){

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

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

		if(!prime[i]){

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

			prime[j] = 1;

		}

	}

}

void caculateNumber(){

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

		dp[i] = (!prime[i] && !prime[(i+1)/2]) ? dp[i-1] + 1 : dp[i-1];

	}

}

int main(){

	cin >> m;

	caculatePrime();

	caculateNumber();

	while(m--){

		cin >> li >> ri;

		cout << dp[ri] - dp[li-1] << endl;

	}

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 2.391948925627182x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+5;

int m,li,ri;

int prime[maxn];

int dp[maxn];

void caculatePrime(){

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

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

		if(!prime[i]){

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

			prime[j] = 1;

		}

	}

}

void caculateNumber(){

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

		dp[i] = (!prime[i] && !prime[(i+1)/2]) ? dp[i-1] + 1 : dp[i-1];

	}

}

int main(){

	cin >> m;

	caculatePrime();

	caculateNumber();

	while(m--){

		cin >> li >> ri;

		cout << dp[ri] - dp[li-1] << endl;

	}

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.521845723655437x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+5;

int m,li,ri;

int prime[maxn];

int dp[maxn];

void caculatePrime(){

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

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

		if(!prime[i]){

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

			prime[j] = 1;

		}

	}

}

void caculateNumber(){

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

		dp[i] = (!prime[i] && !prime[(i+1)/2]) ? dp[i-1] + 1 : dp[i-1];

	}

}

int main(){

	cin >> m;

	caculatePrime();

	caculateNumber();

	while(m--){

		cin >> li >> ri;

		cout << dp[ri] - dp[li-1] << endl;

	}

	return 0;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 1.2264938984108522x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+5;

int m,li,ri;

int prime[maxn];

int dp[maxn];

void caculatePrime(){

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

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

		if(!prime[i]){

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

			prime[j] = 1;

		}

	}

}

void caculateNumber(){

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

		dp[i] = (!prime[i] && !prime[(i+1)/2]) ? dp[i-1] + 1 : dp[i-1];

	}

}

int main(){

	cin >> m;

	caculatePrime();

	caculateNumber();

	while(m--){

		cin >> li >> ri;

		cout << dp[ri] - dp[li-1] << endl;

	}

	return 0;

}
// Slower C++ solution:
#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;

		}

}

// Faster C++ solution for the same problem (measured speedup: 1.2250880084280635x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+5;

int m,li,ri;

int prime[maxn];

int dp[maxn];

void caculatePrime(){

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

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

		if(!prime[i]){

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

			prime[j] = 1;

		}

	}

}

void caculateNumber(){

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

		dp[i] = (!prime[i] && !prime[(i+1)/2]) ? dp[i-1] + 1 : dp[i-1];

	}

}

int main(){

	cin >> m;

	caculatePrime();

	caculateNumber();

	while(m--){

		cin >> li >> ri;

		cout << dp[ri] - dp[li-1] << endl;

	}

	return 0;

}
// Slower C++ solution:
#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;

		}

}

// Faster C++ solution for the same problem (measured speedup: 2.3918962709598444x):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+5;

int m,li,ri;

int prime[maxn];

int dp[maxn];

void caculatePrime(){

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

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

		if(!prime[i]){

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

			prime[j] = 1;

		}

	}

}

void caculateNumber(){

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

		dp[i] = (!prime[i] && !prime[(i+1)/2]) ? dp[i-1] + 1 : dp[i-1];

	}

}

int main(){

	cin >> m;

	caculatePrime();

	caculateNumber();

	while(m--){

		cin >> li >> ri;

		cout << dp[ri] - dp[li-1] << endl;

	}

	return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 2.7366973944762853x):
#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;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



bool x[100001];

int q,l[100001],r[100001],ans[100001];



void sh()

{

	int i,j;

	x[0]=1;x[1]=1;

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

	{

		if(x[i]==0)

		{

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

	        {

	        	x[j]=1;

            }

		}

	}  

}



void sh2()

{

	int i;

	for(i=99999;i>=3;i-=2)

	{

		if(x[i]==0)

		{

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

		}

	}

	

}



void sh3()

{

	int i;

	ans[3]=1;

	for(i=4;i<=99999;i++)

	{

		if(x[i]==0)ans[i]=ans[i-1]+1;

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

	}	

}



int main()

{

	cin>>q;

	sh();sh2();sh3();

	int i,j;

	for(i=1;i<=q;i++)cin>>l[i]>>r[i];

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

	{

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

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.260294120145997x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 3.075012550888787x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.956435879804522x):
#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;

}
// Slower C++ solution:
#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;

} 

// Faster C++ solution for the same problem (measured speedup: 1.5767410795416474x):
#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;

}
// Slower C++ solution:
#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;

		}

}

// Faster C++ solution for the same problem (measured speedup: 1.5749337126301193x):
#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;

}
// Slower C++ solution:
#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;

		}

}

// Faster C++ solution for the same problem (measured speedup: 3.0749448597432143x):
#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;

}