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

#include <iostream>



using namespace std;



template <size_t N>

struct Ans

{

    bool is_prime[N];

    int count[N + 1];

    constexpr Ans() : is_prime(), count()

    {

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

        {

            is_prime[i] = true;

        }

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            if (is_prime[i])

            {

                size_t cur = i * 2;

                while (cur < N)

                {

                    is_prime[cur] = false;

                    cur += i;

                }

            }

        }



        count[0] = 0;

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

        {

            count[i + 1] = count[i];

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

            {

                count[i + 1] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto is_prime = Ans<100010>();

    int q;

    cin >> q;

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

    {

        int a, b;

        cin >> a >> b;

        cout << (is_prime.count[b + 1] - is_prime.count[a]) << endl;

    }

}

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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    short ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();



    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    int ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();

    int Q;

    cin >> Q;

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

    {

        int l, r;

        cin >> l >> r;

        cout << (solver.ans[r] - solver.ans[l - 1]) << endl;

    }

}


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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    short ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();



    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    int ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    ios::sync_with_stdio(false);



    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();

    int Q;

    cin >> Q;

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

    {

        int l, r;

        cin >> l >> r;

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    short ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();



    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    int ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);



    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();

    int Q;

    cin >> Q;

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

    {

        int l, r;

        cin >> l >> r;

        auto ans = solver.ans[r] - solver.ans[l - 1];

        cout << ans << '\n';

    }

}


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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    short ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();



    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    int ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();

    int Q;

    scanf("%d", &Q);

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

    {

        int l, r;

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

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    short ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();



    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    int ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();

    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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



using namespace std;



int parse_int()

{

    int n = 0, c;

    while (1)

    {

        c = getchar_unlocked();

        if ('0' <= c && c <= '9')

            n = n * 10 + c - '0';

        else

            break;

    }

    return n;

}



template <size_t N>

struct Solver

{

    bool is_prime[N + 1];

    short ans[N + 1];

    constexpr Solver() : is_prime(), ans()

    {

        is_prime[0] = false;

        is_prime[1] = false;

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

        {

            is_prime[i] = true;

        }

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

        {

            if (is_prime[prime])

            {

                for (size_t q = prime * 2; q <= N; q += prime)

                {

                    is_prime[q] = false;

                }

            }

        }

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

        {

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

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

            {

                ans[i] += 1;

            }

        }

    }

};



int main()

{

    constexpr auto M = 100000;

    constexpr auto solver = Solver<M>();



    int Q = parse_int();

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

    {

        int l = parse_int();

        int r = parse_int();

        auto ans = solver.ans[r] - solver.ans[l - 1];

        printf("%d\n", ans);

    }

}


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

using namespace std;

#define ll long long int

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

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000



int prime[100010];



int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    prime[0] = 1;

    prime[1] = 1;

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

        int j = 2;

        while(i * j <= 100000) {

            prime[i*j] = 1;

            j++;

        }

    }

    int sum[100010] = {};

    REP(i, 1, 100000) {

        int flag = 0;

        if (prime[i] == 0 && prime[(i+1)/2] == 0) flag = 1;

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

    }



    int Q; cin >> Q;

    int l, r;

    rep(i, Q) {

        cin >> l >> r;

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

    }



    return 0;

}


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

using namespace std;

#define ll long long int

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

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

#define REP(i,s,t) for( int i = s; i <= t; i++ )

#define RREP(i,s,t) for( int i = s; i >= t; i-- )

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF 2000000000

#define mod 1000000007

#define INF2 1000000000000000000



bool isPrime[100010];



void set_prime() {

    rep(i, 100010) isPrime[i] = true;

    isPrime[0] = isPrime[1] = false;

    REP(i, 2, 1000) {

        int j = 2;

        while(i * j <= 100000) {

            isPrime[i * j] = false;

            j++;

        }

    }

}

int sum[100010];

int main(void)

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    set_prime();

    int Q; cin >> Q;

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

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

            sum[i] = 1;

        }

    }

    rep(i, 100000) sum[i + 1] += sum[i];

    while(Q--) {

        int l, r;

        cin >> l >> r;

        cout << sum[r] - sum[l - 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;

typedef pair<ll, ll> P;



int Q, l[100001], r[100001];



int main(){

    cin >> Q;

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



    vector<int> nums(100001);

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

        nums[i] = i;

    }



    vector<int> ans;

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

        if(nums[i] == 0) continue;

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

            nums[i*j] = 0;

        }

        int x = (i + 1) / 2;

        if(nums[x] != 0 && i != 2){

            ans.push_back(i);

        }

    }



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

        auto li = lower_bound(ans.begin(), ans.end(), l[i]);

        auto ri = upper_bound(ans.begin(), ans.end(), r[i]);

        int cnt = ri - li;

        cout << cnt << endl;

    }

}

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

using namespace std;



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

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



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; }



typedef long long ll;

typedef pair<int, int> P;



const int MAX = 200005;

const int INF = 1001001001;

const int MOD = 1000000007;



bool isPrime(int x) {

    if (x == 1) return false;

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

        if (x % i == 0) return false;

    }

    return true;

}



int main(){

    int Q;

    cin >> Q;



    vector<int> L(Q), R(Q);

    rep(i, Q) cin >> L[i] >> R[i];



    int N = *max_element(R.begin(), R.end());



    vector<int> sum(N+1);

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

        if (isPrime(x) && (x+1) % 2 == 0 && isPrime((x+1)/2)) {

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

        } else {

            sum[x] = sum[x-1];

        }

    }



    rep(i, Q) {

        L[i]--;

        cout << sum[R[i]] - sum[L[i]] << endl;

    }

}

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

#include <iostream>

#include <map>

#include <numeric>

#include <set>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <vector>

#include <queue>

#define MOD (1000000007l)

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



using namespace std;



int main(void) {

  vector<bool> primes(100010, true);

  primes[0] = false;

  primes[1] = false;

  for (long i = 2; i < 100010; i++) {

    if (not primes[i]) continue;

    for (long j = i * 2; j < 100010; j += i) primes[j] = false;

  }



  vector<long> accum(100010, 0);

  long count = 0;

  for (long i = 1; i <= 100000; i+= 2) {

    if (primes[i] and primes[(i + 1) / 2]) count++;

    accum[i] = count;

  }



  long Q;

  cin >> Q;



  rep (i, Q) {

    long l, r;

    cin >> l >> r;

    if (l == 1) cout << accum[r] << endl;

    else cout << accum[r] - accum[l-2] << 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]);

}

}


// Fastest known solution for this problem: