Factorial of N (big integer multiplication) -- 51Nod, factorial -- 51nod
Fortunately, I wrote an extra-large integer computation, and successfully compiled. (This is the implementation code of a big integer multiplication)
Let's put it simply. The idea of the big Integer Operation is to store numbers in arrays and simulate carry by arrays.
Of course, this uses one storage space. If you want to optimize the time, you can consider every four storage space.
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#include <queue>#include <stack>using namespace std;int a[37000],k;void chengfa(int n){ int j,i,temp,carry; a[0]=1;k=1; for(i=2;i<=n;i++) { carry=0; for(j=0;j<k;j++) a[j]*=i; for(j=0;j<k;j++) { temp=carry+a[j]; a[j]=temp%10; carry=temp/10; } while(carry) { a[k++]=carry%10; carry/=10; } }}int main(){ int n,flag; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); chengfa(n); flag=0; for(int i=k-1; i>=0; i--) { if(a[i]!=0||flag==1) { printf("%d",a[i]); flag=1; } } printf("\n"); }}