Problem Description
input a positive integer n, the output n! Value.
Wherein the n-!. 1 = 2 . 3 n-* ... *.
Algorithm Description
n! Possible large but finite integer range representation can be a computer, the method requires the use of high-precision calculations. A use of an array to represent a large integer a, A [0] is represented by a bit, A [. 1] represents a ten, and so on.
The integer a is multiplied by a k becomes each element in the array A are multiplied by k, the corresponding note processing carry.
First, a 1 is set, then by 2, by 3, when multiplied to n, i.e., to obtain a n! Value.
Input format
input contains a positive integer n, n <= 1000.
Output format
output n! Exact value.
Input Sample
10
Sample Output
3628800
C ++ code:
#include<bits/stdc++.h>
using namespace std;
vector<int> mul(vector<int> &A,int b){
vector<int> c;
int t=0;
for(int i=0;i<A.size()||t;i++){
if(i<A.size()) t+=A[i]*b;
c.push_back(t%10);
t/=10;
}
return c;
}
int main(){
int n;
vector<int> A,C;
string a="1";
cin>>n;;
for(int i=a.size()-1;i>=0;i--) A.push_back(a[i]-'0');
while(n>=1){
A=mul(A,n--);
}
for(int i =A.size()-1;i>=0;i--) printf("%d",A[i]);
return 0;
}