这是在网上法官上提交的一部法典,用于生成主要数字,但Im正在陷入分化错误。 目标是generate prime number between the given range m to n (with n > m)。 采用Etosthenes算法实施。 请告诉我,什么情况会错。 感谢:
#include <stdio.h>
#include <math.h>
int main(){
long int m,n,c1,c2,c3;
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&m,&n);
//create prime list
short int *prime;
prime = (short int*)malloc((n-m)*sizeof(short int));
//fill list with 0 - prime
for(c1 = 2; c1 <= n; c1++){
prime[c1] = 1;
}
//set 1 and 0 as not prime
prime[0]=0;
prime[1]=0;
//find primes then eliminate their multiples (0 = prime, 1 = composite)
for(c2 = 2;c2 <= (int)sqrt(n)+1;c2++){
if(prime[c2]){
c1=c2;
for(c3 = 2*c1;c3 <= n; c3 = c3+c1){
prime[c3] = 0;
}
}
}
//print primes
for(c1 = m; c1 <=n; c1++){
if(prime[c1]) printf("%d
",c1);
}
}
return 0;
}