NUMFACT- SIGFPE in few test cases

I am unable to pass all the test cases.Can someone please tell me where I am going wrong.
Following is the link to my code: http://www.codechef.com/viewsolution/3949516

Thanks in advance.

Take care of the following points:

  1. The array declared inside while(t) is int a[n] and the statement, scanf("%d",&a[n]); is therefore wrong, as the valid index of array elements declared with size n is from 0 to n-1 so change it to scanf("%d",&a[n-1]);

  2. Now, for example, if a[n-1], is entered as 93923(note: this is a prime number) in that case the value of i in loop while(a[n]!=1) will go beyond 167(due to i++ in else part) as it not divisible by any number other than 1 and itself. When i becomes more than the last valid index of the array prime[168],i.e. 167, then the use of it in a[n]%prime[i] causes run time error. The algorithm in your solution is also not counting the prime numbers greater than 997(i.e., when a[n] is prime no. >997, which is the last value of prime[168]). Also, when there is any factor greater than 997( for example: 2894=1447*2), it causes run time error as i goes beyond 167.

  3. To make the corrections mentioned in point 2,there is a need to generate prime numbers till 1000000, this should also take into account primes greater than 997. To store these primes increase your array sizes accordingly and use a fast algorithm to generate primes.