Skip to content

Commit a872466

Browse files
authored
Update prim1.cpp
1 parent f7a8cb3 commit a872466

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

codechef/prim1.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// https://www.codechef.com/problems/PRIME1
2+
#include <iostream>
3+
using namespace std;
4+
5+
bool isPrime(long long int n)
6+
{
7+
if(n <=1)
8+
return false;
9+
for(int i =2; i<n; i++)
10+
{
11+
if(n % i == 0)
12+
return false;
13+
}
14+
return true;
15+
}
16+
17+
void generate_primes()
18+
{
19+
long long int a, b;
20+
cin >> a >> b;
21+
if(a <=1 || b<=1)
22+
return;
23+
for(int i =a+1 ; i<b; i++)
24+
{
25+
if(isPrime(i))
26+
cout<<i<<endl;
27+
}
28+
cout<<endl;
29+
}
30+
31+
int main()
32+
{
33+
long long int test_cases;
34+
cin >> test_cases;
35+
while(test_cases--)
36+
{
37+
generate_primes();
38+
}
39+
return 0;
40+
}

0 commit comments

Comments
 (0)