HDOJ-1018 Big Number

http://acm.hdu.edu.cn/showproblem.php?pid=1018

题意:给出一个数n,输出n的阶乘的位数

汗Σ( ° △ °|||)︴
刚开始还准备上大数乘法 然而10000的阶乘结果就已经接近40000位
10^7的阶乘...

正:对于一个数n 求其位数可以用 log10(n) + 1 求得
所以 对于N! 其位数= log10(1*2*...*(N-1)*N) +1 = log10(1)+log10(2)+..+log10(N-1)+log10(N) + 1
【简单粗暴

# include <stdio.h>
# include <math.h>

int main()
{
	int t, num;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d", &num);
		double len = 0;
		for(int i = 1; i <= num; i++)
		{
			len += log10((double)i);
		}
		printf("%d\n",(int)len + 1);
	}

	return 0;
}

  

时间: 2024-10-06 16:06:37

HDOJ-1018 Big Number的相关文章

hdoj 1492 The number of divisors(约数) about Humble Numbers 【数论】【质因子分解 求和】

定理:一个正整数 n 可以用素因子唯一表示为 p1^r1 * p2^r2 * ... pk^rk (其中 pi 为素数) , 那么这个数的因子的个数就是,(r1+1)*(r2+1)*...*(rk+1). 理解:为什么是加1之后再相乘,因为一个数的的因子数至少为1和他自身,但因为r1,r2..可以为0,所以因子的个数为(r1+1)... 拓展一下: 定理1: 一个正整数 n 可以用素因子唯一表示为 p1^r1 * p2^r2 * ... pk^rk (其中 pi 为素数) , 那么这个数的因子的

HDU 1018 Big Number 数学题解

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of

水题 HDOJ 4727 The Number Off of FFF

题目传送门 1 /* 2 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const in

HDU 1018 Big Number (简单数学)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25649    Accepted Submission(s): 11635 Problem Description In many applications very large integers numbers are required. Some of these

HDU 1018 Big Number (数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x) + 1; 所以n!的位数 = (int)log10(1*2*3*.......n) + 1; = (int)(log10(1) + log10(2) + log10(3) + ........ log10(n)) + 1; 1 #include<cstdio> 2 #include<cs

HDU 1018 -- Big Number (Stirling公式求n!的位数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40551    Accepted Submission(s): 19817 Problem Description In many applications ver

hdoj.3826 Squarefree number

hdoj 3826 Squarefree number 考虑一个数能被完全平方数整除,当且仅当对其分解质因数以后,至少有一个质数的指数\(≥2\) 借用试除法分解质因数的思路,大于\(\sqrt[3]{N}\)的质因子至多只有一个.那么,大于 \(\sqrt[3]{N}\) 的质因数的平方整除 $N $ 的个数至多也只有一个,而且指数至多为 \(2\) ,因为指数再大或者再乘上一个等数量级的完全平方数都会超过 $ 10^{18} $ 的数据范围. 然后就筛出 \(\sqrt[3]{10^{18}

HDOJ Guess the number 3337【神题-抓取杭电后台输出数据】

Guess the number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7077    Accepted Submission(s): 1626 Problem Description AekdyCoin is the most powerful boy in the group ACM_DIY, whose signatur

HDU 1018 Big Number (log函数求数的位数)

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of

HDOJ 4937 Lucky Number

当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 521    Accepted Submission(s): 150 Probl