#include<iostream>
using namespace std;
int main()
{
int test;
cin>>test;
while(test--)
{
int start,end,m;
cin>>start;
cin>>end;
bool arr[end];
for(int i=0;i<end;i++)
arr[i]=true;
for(int i=2;(i*i)<=end;i++)
{
for(int p=2;(p*i)<=end;p++)
{
m=(p*i-1);
arr[m]=false;
}
}
for(int i=start-1;i<=end;i++)
{
if(arr[i]!=0&&i!=0)
cout<<i+1<<endl;
}
}
return 0;
}
Yogesh_9
0
Newbie Poster
Recommended Answers
Jump to PostWhat is the question ?
If you want an C++ algorthm to generate prime numbers just googleit. There are alot of examples.
Jump to PostYou need to change all of your comparisons in your loops from
<= end
to< end
. The reason for this is ifi
orp
equalsend
then you are one past the end of the array and reading data that my not belong to you and thus returning …
All 8 Replies
Alberto Bucur
0
Junior Poster
Yogesh_9
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
Alberto Bucur
0
Junior Poster
Alberto Bucur
0
Junior Poster
Yogesh_9
0
Newbie Poster
Alberto Bucur
0
Junior Poster
StuXYZ
731
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.