hdu 1042

高精度大数运算其实就是由于数字过大必须要用数组来存数据

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

#include<stdio.h>
#include<math.h>
#include<iterator>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
	int a[100005],i,j,num,count,k;
	while(scanf("%d",&num)!=EOF)
	{
		a[0]=1;
		count=1;

		for(i=1;i<=num;i++)
		{
			k=0;
			for(j=0;j<count;j++)
			{
				int temp=a[j]*i+k;
				a[j]=temp%10;
				k=temp/10;
			}
			while(k)
			{
				a[count++]=k%10;//在上边的基础上进行拓展位数
				k/=10;
			}
		}
		for(i=count-1;i>=0;i--)
			cout<<a[i];
		cout<<endl;

	}
	return 0;
}

  

时间: 2024-10-13 07:34:44

hdu 1042的相关文章

hdu 1042 N!(大数阶乘,转化为100000这样的比较大的进制)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54172    Accepted Submission(s): 15365 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one

HDU 1042 大数阶乘

B - 2 Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1042 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. Outpu

HDU 1042 N! 参考代码

请问DIY题目做不来的队员:听进去了吗?去消化吸收了吗?能百度一下吗? 请问集训队员:有兴趣吗?有团队合作精神吗?有责任感吗?能坚持吗?能自主学习吗?能承受挫败吗? HDU 1042 N! 题意:Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! (题目链接) #include <iostream> using namespace std; //每个数组元素存放5位数 const int MAX=1000000; //

HDU 1042 N!

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1042Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N! InputOne N in one line, process to the end of file. OutputFor each N, output N! in one line. Sample Input123 Sample

HDU 1042 N! (大数阶乘,还是Java大法好,C也不能错过!!!)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 73270    Accepted Submission(s): 21210 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in o

HDU - 1042 - N! - JAVA

http://acm.hdu.edu.cn/showproblem.php?pid=1042 大数嘛,直接用JAVA. 为什么要开64路?好像我觉得会快一点--其实并没有快-- import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while

HDU 1042 大数计算

这道题一开始就采用将一万个解的表打好的话,虽然时间效率比较高,但是内存占用太大,就MLE 这里写好大数后,每次输入一个n,然后再老老实实一个个求阶层就好 java代码: 1 /** 2 * @(#)Main.java 3 * 4 * 5 * @author 6 * @version 1.00 2014/12/21 7 */ 8 import java.util.*; 9 import java.math.*; 10 11 public class Main { 12 //public stati

HDU 1042 N!

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 83996    Accepted Submission(s): 24766 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in on

HDU 1042 N! 高精度乘法

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 题目意思很简单,就是让你求N的阶乘,但是N的范围有10000,所