HDU 1018 Big Number (log函数求数的位数)
the number.
2
10
20
7
19
log10(123456)=5.09151;
log10(1.23456*10^5)=log10(1.23456)+log10(10^5)=0.09151+5;
故int(log10(n))+1 就是n的位数
2、斯特林近似公式:n!≈sqrt(2*π*n)*(n/e)^n。
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
int i,t,n;
double ans;
cin>>t;
while(t--){
cin>>n;
ans=0;
for(i=1;i<=n;i++) {
ans+=log10(double(i));
}
printf("%d\n",int(ans)+1);
}
return 0;
}
HDU 1018 Big Number (log函数求数的位数)的更多相关文章
- HDU 1018 Big Number
LINK:HDU 1018 题意:求n!的位数~ 由于n!最后得到的数是十进制,故对于一个十进制数,求其位数可以对该数取其10的对数,最后再加1~ 易知:n!=n*(n-1)*(n-2)*...... ...
- C++:函数求数根(总算写出来了。。。。)
[问题描述] 数根问题递归求解:输入n个正整数(输入格式中第一行为整数个数n,后续行为n个整数),输出各个数的数根.数根的定义:对于一个正整数n,我们将它的各个位相加得到一个新的数字,如果这个数字是一 ...
- HDU 1018 Big Number 斯特林公式
Big Number 题意:算n!的位数. 题解:对于一个数来算位数我们一般都是用while去进行计算,但是n!这个数太大了,我们做不到先算出来在去用while算位数. while(a){ cnt++ ...
- nefu26(求数的位数)
Description 根据密码学需要,要计算某些数的阶乘的位数. Input 第一行为整数n ,接下来 n 行, 每行1个数m (1 ≤ m ≤ 10^7) . Output 输出m的阶乘的位数. ...
- hdu 1018:Big Number(水题)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1018 Big Number (数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 解题报告:输入一个n,求n!有多少位. 首先任意一个数 x 的位数 = (int)log10(x ...
- HDU 1018 Big Number【斯特林公式/log10 / N!】
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1018 Big Number 数学题解
Problem Description In many applications very large integers numbers are required. Some of these app ...
- HDU 1018 Big Number (阶乘位数)
题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...
随机推荐
- Leetcode 54:Spiral Matrix 螺旋矩阵
54:Spiral Matrix 螺旋矩阵 Given a matrix of m x n elements (m rows, n columns), return all elements of t ...
- css的存在形式
1.css的样式,可以写在head头中: 1).通过ID(#CC{}) 2).通过class (.cc{}) 2.可以将样式,单独写入css的某一个页中 1)通过在head头中,引改该css样式,通过 ...
- vue跨域解决方法 及设置api路径方法
vue项目中,前端与后台进行数据请求或者提交的时候,如果后台没有设置跨域,前端本地调试代码的时候就会报“No 'Access-Control-Allow-Origin' header is prese ...
- 漫谈WEB前端学习路线
- super在python中有什么用
所属网站分类: python高级 > 面向对象 作者:阿里妈妈 链接:http://www.pythonheidong.com/blog/article/74/ 来源:python黑洞网 有什么 ...
- UVa Sculpture(离散化 floodfill)
题意: 给定n个立方体的一个顶点坐标和3边长度, 问这些立方体组成的雕塑的表面积和体积, 坐标都是整数,n最大为50, 最大为500, 边长最大也是500. 分析: 继UVa221后又一道离散 ...
- jz2440开发板烧写裸板
前提:手头没有openjtag,电脑上没有并口, 实现方法:jlink下载,nor上的uboot下载 关键点是用jlink下载uboot 1,使用jlink进行烧写,其中注意的是jlink只能烧写no ...
- nativeLibraryDirectories=[/data/app/com.lukouapp-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libxxxx.so
一开始我遇到的问题是,如果手机有SD卡槽,则不管有没有插卡,都会闪退,打日记后发现是找不到so文件.报错日记如下: nativeLibraryDirectories=[/data/app/com.lu ...
- CodeForcesGym 100517H Hentium Scheduling
Hentium Scheduling Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- [POJ2774][codevs3160]Long Long Message
[POJ2774][codevs3160]Long Long Message 试题描述 The little cat is majoring in physics in the capital of ...