questions:https://hack.codingblocks.com/dcb/p/56
answers:https://ide.codingblocks.com/#/s/23682
2/6 test cases
Facto sum problem daily byte code
2 mistakes:
- fact must be initialised inside the āiā loop.
- Basically you can not compute factorial of numbers >10 and store them in integer format. Thus you should take mod 107 while computing factorial itself.
Here is the corrected version.
#include
using namespace std;
int main() {
int n,fact=1,sum=0,arr[10];
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
fact=1;
for(int j=1;j<=arr[i];j++)
{ fact=(fact*j)%107;
}
sum=(sum+fact)%107;
}
cout<<(sum)%107;
return 0;
}
1 Like