HDU-1018 BigNumber】的更多相关文章

LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*......*3*2*1 ∴lg(n!)=lg(n)+lg(n-1)+lg(n-2)+......+lg(3)+lg(2)+lg(1); 代码: #include <iostream> #include <cstdio> #include <cmath> using namespace…
题目链接: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; #include<cstdio> #include<cstrin…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35382    Accepted Submission(s): 16888 Problem Description In many applications very large integers numbers are required. Some of these…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21106    Accepted Submission(s): 9498 Problem Description In many applications very large integers numbers are required. Some of these…
题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w = lg103 = 3. 因此只要求lgn 向下取整 +1就是位数.然后因为阶乘比如5阶乘的话是5 * 4 * 3 * 2 * 1.位数就满足lg 5 * 4 * 3 * 2 * 1 = lg5 + lg4 + lg3 + lg2 + lg1.用加法就不会超过数字上限. 当然这是十进制下得.如果是m进制下 ,…
数学题  用的这个方法比较烂 g++超时  c++ 406ms /************************************************************************* > Author: xlc2845 > Mail: xlc2845@gmail.com > Created Time: 2013年10月16日 星期三 20时47分16秒 *****************************************************…
Problem Description Inmany applications very large integers numbers are required. Some of theseapplications are using keys for secure transmission of data, encryption, etc.In this problem you are given a number, you have to determine the number ofdig…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 38886    Accepted Submission(s): 18889 Problem Description In many applications very large integers numbers are required. Some of these…
题意是求 n 的阶乘的位数. 直接求 n 的阶乘再求其位数是不行的,开始时思路很扯淡,想直接用一个数组存每个数阶乘的位数,用变量 tmp 去存 n 与 n - 1 的阶乘的最高位的数的乘积,那么 n 的阶乘的位数就等于 n - 1 的阶乘的位数加 tmp 的位数再减去 1. 但这种做法是不对的,例如有可能最高位与 n 的乘积结果是 99,而其实 n 与其他位的乘积结果是能进到这一位的,也就是说实际应该在 n - 1 的阶乘位数上增加 2 ( 3 -1 ) 位.而在对样例测试时也发现 n 为 10…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34084    Accepted Submission(s): 16111 Problem Description In many applications very large integers numbers are required. Some of these…