FACTO SUM wrong ans in 5th testcase

https://ide.codingblocks.com/#/s/13600
https://hack.codingblocks.com/contests/c/452/56

#include
#include
using namespace std;
int main() {
unsigned long long int n,s=0,p=1,c=1,i;
cin>>n;
int a[n];
sort(a,a+n);
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++){
while((c-1)!=a[i])
p=p*(c++);
s=s+p;
}
cout<<s%107;
return 0;
}

Please provide the Qn. link

https://hack.codingblocks.com/practice/p/359/56

Hello Amritanshu ! ur code is fine except one thing actually you misunderstand the modulo property . Suppose one of the array elements becomes larger , so u are finding the factorial first which in this case u can’t . So u need to take modulo with 107 in every iteration of while loop . Okay , go through this you will be able to understand https://ide.codingblocks.com/#/s/13690 .
Any doubt ??

1 Like

my code is giving run error in 5th test case.plz help
https://ide.codingblocks.com/#/s/22291

@r11
for which question ?

For the facto sum problem of hacker blocks.the question says input nos from user and then evalute sum of factorial modulo 107 .but since no. is very big so properties of modulo had to be used but even then for fifth test case it is giving run error.

For the facto sum problem on hacker blocks.that is to find the modulo 107 of the sum of the factorial of numbers input from users. the numbers being input are very large.i have all the modulus properties in my code still i am getting run error in 5th test case.pls tell what is wrong with my code.

i submitted the solution and it worked for me.

here’s my submission for help.
please upload your solution if you want me to check.
https://ide.codingblocks.com/#/s/22564

https://ide.codingblocks.com/#/s/22701

See this solution with recursion. It is based on your submission.
Recursion may fail for numbers >10^5.

@r11 Only issue is for num=0. Handle it separately .