This is Discussion thread about Virat and Factorials
Discussion About Virat and Factorials
Tip: Use STRING MULTIPLICATION
#include
#include
#include<bits/stdc++.h>
#define l unsigned long long int
using namespace std;
string string_multiplication(string s1,string s2){
l m = s1.size(); l n = s2.size();
vector v(m+n,0);
for(l i=m-1;i>=0;i--){
l p = (m-1)-i;
for(l j=n-1;j>=0;j--){
l sum = v[p] + (s1[i]-'0') * (s2[j]-'0');
v[p] = sum % 10;
v[p+1] += sum/10;
p++;
}
}
////////////////////
// cout<<"Checking going “<<endl;
// for(l i=v.size()-1;i>=0;i–){
// cout<<v[i]<<” ";
// }
// cout<<endl;
////////////////////
string out = “”;
int j = v.size() - 1;
while(j>= 0 && v[j] == 0){
j–;
}
if(j == -1){
out = “0”;
}
for(;j>=0;j–){
out = out + to_string(v[j]);
}
return out;
}
int main(){
l n; cin>>n;
string ans = “1”;
for(l i=1;i<=n;i++){
ans = string_multiplication(ans,to_string(i));
}
cout<<ans<<endl;
return 0;
}
sir what is wrong in the code???