Given N numbers, calculate sum of their factorial modulo 107. (Note it is not 10^7)?

Solution-Some of the test cases are failing

#include

using namespace std;

int main() {

char a[20];

cin>>a;

int sum=0;

for(int i=0;a[i]!=’\0’;i++)

{

int d=1;

for(int j=1;j<=a[i]-‘0’;j++)

d=d*j;

sum=sum+d;

}

cout<<(sum%107);

return 0;

}

# Facto sum (sum of their factorial modulo 107)

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

i removed the errors but it is failing for basic cases like

INPUT:

4

1 2 3 4

OUTPUT:

24

EXPECTED OUTPUT:

33

it has passed ony 2 test cases …and 4 ( 1 2 3 4) is giving correct ans…

#include <bits/stdc++.h>

using namespace std;

int main() {

int a;

cin>>a;

int sum=0;

for(int i=0;i<a;i++)

{

int k;

cin>>k;

int d=1;

for(int j=1;j<=k;j++)

d=d*j;

sum=sum+d;

}

cout<<(sum%107);

return 0;

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

I have made one change and commented it. It should pass all cases now. Do add the problem link so that i can verify first.

thank you , i was actually very confused why my one test case wasnt passing, but taking mod at every step helped. Thanks!!

sir my code for the problem is this…but failing the test cases…

#include<bits/stdc++.h>

using namespace std;

int fac(int n)

{int sum=1;

for(int i=2;i<=n;i++)

{

sum=sum*i;

}

return sum;

}

int main() {

int n;

cin>>n;

int count=0;

while(n!=0)

{int a;

cin>>a;

count=count+fac(a);

n–;

}

cout<<count%107;

return 0;

}