大数阶乘
Time Limit:3000MS Memory Limit:65535K
Total Submit:245 Accepted:99
Description
我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?
Input
输入一个整数m( 0 < m < =5000)
Output
Sample Input
50
Sample Output
30414093201713378043612608166064768844377641568960512000000000000
Hint
C 用数组
Java 用BigInteger
Source
NYIST
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AK1053 { class Program { static void Main(string[] args) { string sb; int i,j,temp,start,sc,N = 1200; while ((sb = Console.ReadLine()) != null) { int n = int.Parse(sb); int[] a = new int[N]; for (a[0] = 1,i = 1; i <= n; i++) for (sc = 0,j = 0; j < N; j++) { temp = a[j] * i + sc;//当前这一位的数乘上i,然后加上后面来的进位 sc = temp / 10;//sc代表进位 a[j] = temp % 10;//本位保留模后的结果 } //数据是倒着存的,即1*2*3*4=24,存是是按420000000...保存的,一直有N=1200位 for (start = N - 1; a[start] == 0; --start) ;//这里是确定从后面哪一位开始输出,从后向前输出 for (; start >= 0; --start) Console.Write(a[start]); Console.WriteLine(); } } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。