i m using Sieve of eratosthenes & getting segfault. I can't understand the reason. Here's my code
#include<stdio.h>
int main(){
long long int i,j;
unsigned short int a[10000001]={1,1};
int b[700000],p[700000],count=0,pc,n,temp;
for(i=2;i<=10000000;i++){
if(a[i]==0){
b[++count]=i;
for(j=i*i;j<=10000000;j+=i)
a[j]=1;}}
while(scanf("%d",&n)!=EOF){
for(i=1;i<=count;i++){
pc=0;
temp=n;
if(b[i]<=n){
while(temp%b[i]==0){
pc++;
temp /=b[i];}}
p[i]=pc;}
if(n==1)
printf("1");
else{
printf("1");
for(i=1;i<=count;i++){
if(p[i])
for(j=1;j<=p[i];j++){
printf(" x %d",b[i]);}}}
printf("\n");}
return(0);}