微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

大数阶乘

A - N!
Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Given an integer N(0 ≤ N ≤ 10000),your task is to calculate N! 
 

Input

One N in one line,process to the end of file. 
 

Output

For each N,output N! in one line. 
 

Sample Input

 
     
1 2 3
 

Sample Output

1 2 6
 数组模拟
我跑了一个10000的数据,显示超时根本算不出来,可提交竟然对了,10000!真是个天文数字。
#include<stdio.h>
#include<string.h>
int main(){
	int a[101000],n,l;
	while(~scanf("%d",&n)){
		memset(a,sizeof(a));
		a[0] =1;
		l=1;
		for(int i=1;i<=n;i++){
			int s = 0,j;
			for( j=0;j<l||s;j++){
				  int z= a[j]*i+s;
					a[j] = z%10;
					s = z/10;
			}
			l=j;
			//printf("%d\n",l);
		}
		for(int j = l-1;j>=0;j--)printf("%d",a[j]);
		printf("\n");
	}
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐