forked from Mugdha-Hazra/codechef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmall factorials Problem Code: FCTRL2.cpp
52 lines (51 loc) · 1.3 KB
/
Small factorials Problem Code: FCTRL2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void multiply(int *a,int &n,int no)
{
int carry=0;
for(int i=0;i<n;i++)
{
int product=a[i]*no + carry;
a[i]=product%10;
carry=product/10;
}
while(carry)
{
a[n]=carry%10;
carry=carry/10;
n++;
}
}
void big_factorial(int number)
{
int *a = new int [1000];
for(int i=0;i<1000;i++)
{
a[i]=0;
}
a[0]=1;
int n=1;
for(int i=2;i<=number;i++)
{
multiply(a,n,i);
}
for(int i=n-1;i>=0;i--)
{cout<<a[i];}
delete []a;
return;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
// cout<<"enter any number:\n";
cin>>n;
big_factorial(n);
cout<<"\n";
}
return 0;
}