I am having a lot of troubles trying to pass this problem. I made this algorithm written in C:
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int m, n;
char primes[100000];
scanf("%d %d", &m, &n);
if (n < 2)
return 0;
if (m <= 2)
printf("%d\n", 2);
if (m % 2 == 0)
m++;
if (m == 1)
m = 3;
for (int i = m; i <= n; i+=2)
{
if (primes[i - m] != 'f')
{
char prime = 't';
for(int j = 3; j * j <= i; j+=2)
if (i % j == 0)
prime = 'f';
if(prime == 't')
printf("%d\n", i);
else
for(int j = 1; i * j <= n; j++)
primes[i * j - m] = 'f';
}
}
printf("\n");
}
return 0;
}
For what I can see (and tested) it works perfectly and it follows the output format that was specified, but I get wrong answer when I submit. Can anyone point me in any direction that could help me realize what I’m doing wrong here?
Thanks!