log10()的运用
来源:互联网 发布:linux安装软件 编辑:程序博客网 时间:2024/05/17 08:12
点击打开链接
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11298 Accepted Submission(s): 4324
Problem Description
Given a positive integer N, you should output the leftmost digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the leftmost digit of N^N.
Sample Input
234
Sample Output
22HintIn the first case, 3 * 3 * 3 = 27, so the leftmost digit is 2.In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.
Author
Ignatius.L
Recommend
We have carefully selected several similar problems for you: 1061 1071 1573 1066 1065
思路:
题意很简单:求N^N的最左边一位的数字.这道题在Math分类中难度为3.用暴力法是绝对会溢出的.
以下内容来自科学计数法-维基百科
科学记数法(英语:Scientific notation)是一种记数的方法。
在科学记数法中,一个数被写成一个1与10之间的实数(尾数)与一个10的次幂的积:
其中 :
- (如果 是一个比1少的小数,或比 10 大,皆可改变 来表达)
- 是一个整数
例子[编辑]
- 782300=7.823×105
- 0.00012=1.2×10−4
- 10000=1×104
假设M=N^N,
则有M=,两边同时取对数log10(M)=log10(a)+n,其中1<=|a|<10,所以log10(a)必然表示的是log10(M)的小数部分,
(因为log10(10)=1,log10(1)=0所以1<=a<10的对数肯定小于1而大于等于0),所以,当务之急是将log10(M)的小数部分找到.
这个比较容易,我们只需要log10(M)-floor(log10(M)) 即可.//floor函数表示向下取整.
#include<stdio.h>#include<math.h>#include<limits.h>int main(){int T;double sum,logSum,DecSum ;scanf("%d",&T) ;while(T--){scanf("%lf",&sum);logSum = sum * log10(sum);DecSum=pow(10.,logSum-(long long)logSum); //用floor或者(long long),不能用(int)printf("%d\n",(int)DecSum);}return 0;}//1000000000
注意边界点:1和1000000000.
拓展:
log10()函数的用法
决窍一:求整数n的位数.1+(int)log10(n).(注意:其中n>0)
#include<stdio.h>#include<math.h>int main(){double T,n;while(scanf("%lf",&n)!=EOF){T=log10(n);printf("%d\n",1+(int)T); //输出n的位数}return 0;}
决窍二:科学计数法中截取整数部分或者小数部分.
科学计数法表示M=a*10^m,其中1<=a<10,m为整数.两边取对数log10(M)=log10(a)+m.log10(a)表示的是小数部分,
m表示的是整数部分.要恢复a的值只需要10^log10(a).
- log10()的运用
- log10
- log10
- HDU 1060 数论, log10的一个用法
- 对于不支持浮点型的10log10运算实现
- (int)log10((int)n)+1 计算位数的几个问题
- log10/log2--求常用对数/以2为底的对数
- log10 ()函数
- log10 () 函数
- log10 函数
- Java Math.log10()方法用法实例教程 - 返回以10为底的double的值
- UVa 10169 - Urn-ball Probabilities ! (预处理+log10计算小数点后连续0的个数)
- HDU 1060 求N^N的最高位 (数学,科学计数法+log10()函数)
- math.h Log log10
- hdu 1018 log10函数
- hdu 1018 log10()
- Java Math.log10()方法
- python log10() 函数
- 【android开发】手机应用管理器的实现之获取应用列表(一)
- 机器学习入门
- Uninstall Trillian with WindowsUninstaller.Org Removal Tips
- 搜狗曝重大安全漏洞 大量用户隐私被泄露
- cef wpf 遇到的问题
- log10()的运用
- nineoldAndroid
- 浏览器模式的问题
- Android是什么 之三手机之硬件形态
- Readonly与Disable的区别
- Android利用SparseArray替换使用HashMap<Integer,E>
- CSS中的position:relative;的作用
- CentOS源码安装 apache2.2.5
- android 图片点击变暗的另一种办法