I tried to solve the problem using sieve of eratosthenes but it works only for the first 5 test cases.
The problem is i think that i can find the next prime number till 100.000 and the task says till 2000.000.000 here is my code:
#include <stdio.h>
#define n 100000
long a[n+1];
int main(void)
{
long int scanned;
scanf("%li",&scanned);
long i,j;
for(i=2;i<=n;i++)
{
a[i]=1;
}
for(i=2;i<=n;i++)
{
for(j=2;j<=n/i;j++)
{
a[i*j]=0;
}
}
for(i=2;i<=n;i++)
{
if(a[i]==1&&i>scanned&&i%2!=0)
{
printf("%ld",i);
break;
}
}
return 0;
}
Thanks a lot by the way
The problem is i think that i can find the next prime number till 100.000 and the task says till 2000.000.000 here is my code:
#include <stdio.h>
#define n 100000
long a[n+1];
int main(void)
{
long int scanned;
scanf("%li",&scanned);
long i,j;
for(i=2;i<=n;i++)
{
a[i]=1;
}
for(i=2;i<=n;i++)
{
for(j=2;j<=n/i;j++)
{
a[i*j]=0;
}
}
for(i=2;i<=n;i++)
{
if(a[i]==1&&i>scanned&&i%2!=0)
{
printf("%ld",i);
break;
}
}
return 0;
}
Thanks a lot by the way