1053 -- 大数阶乘

大数阶乘

Time Limit:3000MS  Memory Limit:65535K
Total Submit:245 Accepted:99

Description

我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?

Input

输入一个整数m( 0 < m < =5000)

Output

输出m的阶乘,并在输出结束之后输入一个换行符

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();
                }
            }
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值