HDU 1042(N! 简单的大数问题)

spoiler posted @ 2011年5月29日 04:15 in 数论 , 1942 阅读

题目分析:这个题目很简单,但是有点细节问题,我在代码里注释一下 就可以了

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int i,j,n,t,lenth,carry,tempt;
	
	while(scanf("%d",&n)!=EOF){
		int s[7201]={1};
		lenth=1;
                 //lenth 记录数组的实际运用长度
		for(i=2;i<=n;i++){
			carry=0;
			for(j=0;j<lenth;j++){
				tempt=s[j]*i+carry;
				carry=tempt/100000;
				s[j]=tempt%100000;
			}
			while(carry){
				                                                    s[lenth++]=carry%100000;
                            //如果有进位 数组运用的实际长度+1
				carry/=100000;
			}
		}
		j=lenth-1;
		printf("%d",s[j--]);
                //注意看好这一步!最高位的前置0不能输出,其他的前
                  //置0要输出
		for(;j>=0;j--)
			printf("%05d",s[j]);
		printf("\n");
	}
	return 0;
}

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter