HDU 1042 大数

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 74633    Accepted Submission(s): 21696


Problem 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
  
  
1 2 3
 

Sample Output
  
  
1 2

6

http://www.cnblogs.com/Su-Blog/archive/2012/08/27/2659172.html 转载

http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目链接

// 又做一道大数

// POJ 2389 两个大数相乘 转载的方法不行

// 必须的拆开 比如888*88 = 8*8+8*8*10+8*8*100+8*8*10+8*8*10*10+8*8*10*100;

//用字符串储存*10就不一0 ;

<pre name="code" class="cpp">#include<iostream>
#define MAX 100000
using namespace std;
int main()
{
    int n,a[MAX];
    int i,j,k,count,temp;
    while(cin>>n)
    {
        a[0]=1;
        count=1;
        for(i=1;i<=n;i++)
        {
            k=0;
            for(j=0;j<count;j++)
            {
                temp=a[j]*i+k;        //如果i过大就不行;
                a[j]=temp%10;
                k=temp/10;
            }
            while(k)//记录进位
             {
                a[count++]=k%10;
                k/=10;
            }
        }
        //for(j=MAX-1;j>=0;j--)
            //if(a[j])
             //   break;//忽略前导0
            for(i=count-1;i>=0;i--)
                cout<<a[i];
            cout<<endl;
    }
    return 0;
}

// JAVA大数

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			BigInteger a = sc.nextBigInteger();
			BigInteger b = sc.nextBigInteger();
			System.out.println(a.multiply(b));
		}
	}

}
// 大数用java 没办法谁叫别人JAVA比较高级 别人封装好了的 去记单词吧



 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值