-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfactorial-of-large-number.cpp
More file actions
49 lines (37 loc) · 984 Bytes
/
factorial-of-large-number.cpp
File metadata and controls
49 lines (37 loc) · 984 Bytes
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
class Solution {
public:
/*
if i give u a inverted array aand a number u will give the product in inverted format as well.
*/
vector<int>multiply(vector<int> & A,int x){
int carry =0;
for(int i=0;i<A.size();i++){
int val=A[i]*x;
val+=carry;
A[i]=val%10;
carry=val/10;
}
while(carry>0){
int temp=carry%10;
A.push_back(temp);
carry=carry/10;
}
return A;
}
/*
koi bhi vector dedo mai tmko reverse krke de dunga
*/
vector<int>invert(vector<int>A){
reverse(A.begin(),A.end());
return A;
}
vector<int> factorial(int N){
vector<int>value;
value.push_back(1);
for(int i=2;i<=N;i++){
value = multiply(value,i);
}
vector<int>ans=invert(value);
return ans;
}
};