Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

### TheAnonymousAMGR's blog

By TheAnonymousAMGR, 2 months ago,

100! is a huge number (around 158 digits). "long long" can store at max 19 digits. We going to get overflow. In Java there is a way to do this but in c++ you can't do this. So we should think another way to solve this problem. Now I explain how to multiply numbers avoid overflow using array. So the maximum possible value for an unsigned is 2 ^ 32 -1.In this case we get in overflow. So I use an array with length 200. here the code

#include <bits/stdc++.h>
using namespace std;
~~~~
int main() {
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
//create a array for 200 digits
int a[200];
a[0]=1;
int digits=1;
// create a for loop for multiply 1 upto n.
for(int i=1;i<=n;i++)
{
// temporary variable which gonna carry all value
int temp=0;

// multiplying every digits in our initial value by the number i.
for(int j=0;j<digits;j++)
{
int x=i*a[j]+temp;
//Storing the last digit
a[j]=x%10;
//for carray over
temp=x/10;
}
//if carry leftover
while(temp>0)
{
a[digits++]=temp%10;
temp/=10;
}
}
//print the array
for(int i=digits-1;i>=0;i--)
{
cout<<a[i];
}
cout<<endl;
}

return 0;
}


[this is my first blog, hopefully anyone learn from here]

• +11

 » 2 months ago, # |   +41 Nice blog, but next time when writing code put it in between a block to make it readable as a c++ codelike this for example vectorv = {1, 1, 2, 3, 5, 8, 13}; This is how you make a block :~~~~ (Put your code here) ~~~~
•  » » 2 months ago, # ^ |   0 Thank you so much sir. God bless you