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

    }

}

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

{

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    auto solver = Solver<100000>();



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

    }

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

    }

}

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

{

    // auto M = 100000;

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    // auto M = 100000;

    auto solver = Solver<100000>();



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

    }

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

    }

}


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

{

    // auto M = 100000;

    auto solver = Solver<100000>();



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

    }

}