HDU 1042 大数

来源:互联网 发布:淘宝给老客户发短信 编辑:程序博客网 时间:2024/06/16 07:14

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
123
 

Sample Output
12

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 100000using 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