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

}

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

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

}

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

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

}

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

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

using namespace std;



#define N 100000



int main(void){

    bool prime[N+1];

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

    {

        prime[i]=true;

    }

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

    {

        prime[i]=false;

    }

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

    {

        if (!prime[i])continue;

        else

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    int likePrime[N]={};

    int likeCnt[N]={};

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

    {

        likeCnt[j]=likeCnt[j-1];

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

        {

            likePrime[j]=true;

            likeCnt[j]++;

        }

    }

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

    int q;

    cin >> q;

    int l[q],r[q];

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

    {

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

    }

    int ans[q]={};

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

    {

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

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

using namespace std;



#define N 100000



int main(void){

    bool prime[N+1];

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

    {

        prime[i]=true;

    }

    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;

            }

        }

    }

    int likeCnt[N]={};

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

    {

        likeCnt[j]=likeCnt[j-1];

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

        {

            likeCnt[j]++;

        }

    }

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

    int q;

    cin >> q;

    int l[q],r[q];

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

    {

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

    }

    int ans[q]={};

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

    {

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

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

using namespace std;



#define N 100000



int main(void){

    bool prime[N+1];

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

    {

        prime[i]=true;

    }

    const int max = sqrt(N);

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

    {

        if (prime[i])

        {

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

            {

                prime[i*j]=false;

            }

        }

    }

    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[q],r[q];

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

    {

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

    }

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

    {

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

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

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

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

    {

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

    }

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

    {

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

}
// Slower C++ solution:
#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 = 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[q],r[q];

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

    {

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

    }

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

    {

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

}
// Slower C++ solution:
#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 = 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[q],r[q];

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

    {

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

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

}
// Slower C++ solution:
#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[q],r[q];

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

    {

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

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

    }

    return 0;

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

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

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

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

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

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

}

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

using namespace std;



#define N 100000



int main(void){

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

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

    const int sqrtN = sqrt(N);

    for (size_t i = 2; i <= sqrtN; 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;

}