大数阶乘
发布时间:2020-12-14 03:27:58 所属栏目:大数据 来源:网络整理
导读:A -? N! Time Limit: 5000 MS????? Memory Limit: 32768 KB????? 64bit IO Format: %I64d %I64u Submit ? Status 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.?
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
?
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("%dn",l); } for(int j = l-1;j>=0;j--)printf("%d",a[j]); printf("n"); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |