the problem: PRINT
I'll be very grateful if someone points me out why I'm getting a wrong answer in the following code. I've been trying to solve for days,thanks in advance.
#include <stdio.h>
#include <string.h>
#include <math.h>
int prime[100000];
int find_prime(int n) /*find_prime finds all primes within sqrt(n),saves them in prime[] array
and returns their count using normal Sieve method*/
{
int i,j,k=0,prime_count=0;
char ara[n+1];
memset(ara,1,sizeof(ara));
for(i=2;i*i<=n;i++){
if(ara[i]==1){
for(j=i*i;j<=n;j+=i)
ara[j]=0;
}
}
for(i=2;i<=n;i++){
if(ara[i]==1){
prime[k++]=i;
prime_count++;
}
}
return prime_count;
}
int main()
{
int i,j,m,n,t,prime_count;
while(scanf("%d",&t)==1){
while(t--){
scanf("%d %d",&m,&n);
prime_count=find_prime(sqrt(n));
char ara[n-m+1];
memset(ara,1,sizeof(ara)); /*to find primes within [m,n] range,we take an array of n-m+1 size
and make every elements 1 */
for(i=0; i<prime_count; i++){ /*using the primes of prime[],we sort out the composite nos within
the range[m,n] and make them 0 */
for(j=m/prime[i],j=j*prime[i]; j<=n; j+=prime[i]){
if(j==2||j==3||j<m)
continue;
else
ara[j-m]=0;
}
}
for(i=m; i<=n; i++){
if(ara[i-m]==1) //indices remaining as 1 are our primes
printf("%d\n", i);
}
}
}
return 0;
}