What runtime error is there in this problem???
#include<stdio.h>
#include<math.h>
int fac(int n){
int c;
short unsigned fact=1;
for (c = 1; c <= n; c++)
fact = fact * c;
return fact;
}
int main(void){
short unsigned T, temp, k=0, i, z, N, ans[100000];
scanf("%hu", &T);
for(temp=0; temp<T; temp++){
scanf("%d", &N);
for(i=0; i<=N; i++)
k=k+(fac(N+i)/((fac(N-i))*(fac(i))*(fac(i))));
z=k%(N*N);
ans[temp]=(N*N)-z;
}
for(temp=0; temp<T; temp++)
printf("\n%hu", ans[temp]);
return 0;
}
Help ASAP
Thanks in advance
Daksh
Hey Daksh,
Are you even getting the correct outputs for the required inputs using your algorithm? I ran your code on ideone, and used 4 as the number of test cases, 2, 3, 5 and 7 as the inputs, and it gave me the wrong output. Even for 2, the answer from your program is 0, not 1, which is the right answer. Or, am I missing something here?
Also, for a variable of type unsigned short, maximum value is 65535 (0xffff), and the limit of test cases in the problem is given as 1 ≤ T ≤ 10^5, so it will fail in that case. That can be the reason for runtime error.
@oldschoolburke: I had uploaded with long unsigned int, but it still gave runtime error.
And the program gives the correct output. Even for 2, it gives 1 and not 0. Please check this link: http://ideone.com/UyTr0g
I have uploaded the code there and the output is correct. please check
What runtime error is it giving? post your solution link on codechef