0
Write a c ++ code to evaluate prime numbers Fromm 500mil to 2 bill and should run in less than 30 seconds.
4 ответов
+ 3
These numbers might be too big for integers. Also, you don't need to check every number since a number > 2 that is divisible by 2 won't be a prime number. So you can start with an odd number and go +=2. The prime number algorithm isn't very efficient, especially not for big numbers, and the variable "count" doesn't seem to be declared anywhere
+ 6
please show your try, and don't post assignments here
+ 1
for(int x=500000000;x<=1000000000;x++){
if(x%2!=0)
{
for(int p=3;p<x/2;p+=2){
if(x%p==0)
count++;}
if(count==1)
cout<<x<<'\n';}
}
0
Thank you Anna