Prime Generator Codechef Solution

Hello Programmers In this post, you will know how to solve the Prime Generator Codechef Solution. The Problem Code: PRIME1

Prime Generator Codechef Solution
Prime Generator Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Ram wants to generate some prime numbers for his cryptosystem. Help him, please! Your task is to generate all prime numbers between two given numbers.

Input

The first line contains t, the number of test cases (less then or equal to 10). Followed by t lines which contain two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output

For every test case print all prime numbers p such that m <= p <= n, one number per line. Separate the answers for each test case by an empty line.

Example

Input:
2
1 10
3 5
Output:
2
3
5
7
3
5

Prime Generator CodeChef Solutions in CPP

#include <iostream>
using namespace std;
bool isPrime(long long int n)
{
    if(n <=1)
        return false;
    for(int i =2; i<n; i++)
    {
        if(n % i == 0)
            return false;
    }
    return true;
}
void generate_primes()
{
    long long int a, b;
    cin >> a >> b;
    if(a <=1 || b<=1)
        return;
    for(int i =a+1 ; i<b; i++)
    {
        if(isPrime(i))
            cout<<i<<endl;
    }
    cout<<endl;
}
int main()
{
    long long int test_cases;
    cin >> test_cases;
    while(test_cases--)
    {
        generate_primes();
    }
    return 0;
}

Disclaimer: The above Problem (Prime Generator) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Counting Pretty Numbers Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad