[Uva623]500!(高精)

Description

求N!

\(N \leq 1000\)

Sample Input

10

30

50

100

Sample Output

10!

3628800

30!

265252859812191058636308480000000

50!

30414093201713378043612608166064768844377641568960512000000000000

100!

93326215443944152681699238856266700490715968264381621468592963895217599993229915

608941463976156518286253697920827223758251185210916864000000000000000000000000

Solution

简单高精即可

Code

#include <cstdio>
#include <cstring>
using namespace std;

const int mod=1e5;
int n,f[1010],len;

int main(){
	while(~scanf("%d",&n)){
		f[1]=1;
		len=1;
		for(int i=2;i<=n;++i){
			int pd=0;
			for(int j=1;j<=len;++j){
				int tmp=f[j]*i+pd;
				pd=tmp/mod;
				f[j]=tmp%mod;
			}
			if(pd>0) f[++len]=pd;
		}
		printf("%d!\n",n);
		printf("%d",f[len]);
		for(int i=len-1;i;i--)
			printf("%05d",f[i]);
		printf("\n");
	}
	return 0; 
} 
posted @ 2017-12-02 10:53  void_f  阅读(139)  评论(0编辑  收藏  举报