标签:for ble include list item def lld 收藏 还需要
输入N(1 <= N <= 10000)
输出N的阶乘
5
120
模拟平时int类型对10取余进位,输出还需要注意格式,%013lld是不足13位左补0.
#include<stdio.h> #define mod 10000000000000 #define N 1000010 #define LL long long LL num[N]; int main() { LL i,j,n; LL k,ans,t; while(scanf("%lld",&n)!=EOF) { ans = 1; num[1] = 1; for(i = 1; i <= n; i ++) { k = 0; for(j = 1; j <= ans; j ++) { t = num[j]*i + k; num[j] = t%mod; k = t/mod;//k保存进位数 } if(k)//如果最后还需要进位 num[++ans] = k; } printf("%lld",num[ans]); for(i = ans-1; i >= 1; i --) printf("%013lld",num[i]); printf("\n"); } return 0; }
标签:for ble include list item def lld 收藏 还需要
原文地址:http://www.cnblogs.com/chengdongni/p/7447436.html