forked from shikharkohli/c---files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigfact.cpp.u1conflict
executable file
·114 lines (107 loc) · 1.54 KB
/
bigfact.cpp.u1conflict
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<iostream>
#include<vector>
#include<cstring>
#define MAX 158
using namespace std;
void print(int arr[])
{
int count = 0,sum=0;
for(int i=0;i<MAX;i++)
{
//sum+=arr[i];
if(arr[i]!=0)
count = 1;
if(count!=0)
{ cout<<arr[i];sum++;}
}
cout<<endl;
//cout<<sum<<endl;
}
void increment(int arr[])
{
arr[MAX-1]+=1;
if(arr[MAX-1] > 9)
{
for(int i=MAX-1;i>=0;i--)
{
if(arr[i]>=10)
{
arr[i-1] += arr[i] / 10;
arr[i]%=10;
}
}
}
}
void mul(int arr[],int num[])
{
//arr*num
int limn=0;
for(int i=0;i<MAX;i++)
{
if(arr[i]!=0)
{
limn=i;
break;
}
}
int lima=0;
for(int i=0;i<MAX;i++)
{
if(arr[i]!=0)
{
lima=i;
break;
}
}
int temp[MAX];
for(int i=0 ; i<MAX;i++)
temp[i]=0;
for(int i=MAX-1;i>=0;i--)
{
for(int j=MAX-1;j>=0;j--)
{
temp[j-((MAX-1)-i)] += arr[j]*num[i];
if(temp[j]>=10)
{
temp[j-1-((MAX-1)-i)] += temp[j-((MAX-1)-i)]/10;
temp[j-((MAX-1)-i)] %= 10;
}
}
}
for(int i=MAX-1;i>=0;i--)
if(temp[i]>=10)
{
temp[i-1]+=temp[i]/10;
temp[i]%=10;
}
for(int i=0;i<MAX;i++)
arr[i]=temp[i];
}
int main()
{
int n=100;
//cout<<"Enter the value of n ";
//cin>>n;
int facts[100][160];
memset(facts,0,sizeof(facts));
for(int x=1;x<=100;x++){
int num[MAX],arr[MAX];
for(int i=0;i<MAX;i++)
num[i]=facts[x-1][i]=0;
num[MAX-1]=1;
facts[x-1][MAX-1]=1;
for(int i=1;i<=x;i++)
{
mul(facts[x-1],num);
increment(num);
}
//print(facts[x-1]);cout<<endl;
}
int t=100;cin>>t;
while(t--)
{
int nums;cin>>nums;
print(facts[nums-1]);
}
return 0;
}