HDOJ--ACMSteps--2.1.8--Leftmost Digit-(取对数,数学)
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).
Output
For each test case, you should output the leftmost digit of N^N.
Sample Input
2
3
4
Sample Output
2
2
Hint
In 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
首先,暴力算是一定会超时的,而且这么大的数也存不下
这道题运用了取对数来缩小运算范围,
推导过程如下:
设M=N^N,则log10(M)=Nlog10(N);
所以M=10^(Nlog10(N));
继续转化
令N=x10^y 例如:155555555=1.5555555510^8;
M=10(N*log10(x*10y)=10(N*(y+log10x))=10(Ny)log10x
so, 只要求出log10x即可
取整即可
HDOJ--ACMSteps--2.1.8--Leftmost Digit-(取对数,数学)的更多相关文章
- hdu acmsteps 2.1.8 Leftmost Digit
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...
- HDU 1060 Left-most Digit
传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Leftmost Digit
Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input ...
- HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1060 Leftmost Digit (数论,快速幂)
Given a positive integer N, you should output the leftmost digit of N^N. InputThe input contains se ...
- HDU 1060 Leftmost Digit
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Leftmost Digit(数学)
Description Given a positive integer N, you should output the leftmost digit of N^N. Input The inp ...
- Leftmost Digit(hdu1060)(数学题)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- [转]整理jquery使用好习惯
1.选择器Selector的使用 1)使用id定位性能最好 1.$("#id") 2)使用标签名定位,性能其次 1.$("p"),$("div ...
- 记2016商大ACM省赛
比赛前三天才得到省赛的非正式参赛名额,总有点哭笑不得,笑的是是我的终究是我的,跑不掉…… 哭的是现在就剩三天了,虽然最近也一直在参加训练赛,但一直是断断续续的,对自己现在的水平并没有太大的信心…… 虽 ...
- Matlab中矩阵的平方和矩阵中每个元素的平方介绍
该文章讲述了Matlab中矩阵的平方和矩阵中每个元素的平方介绍. 设t = [2 4 2 4] 则>> t.^2 ans = 4 164 16 而>> t^2 ans = ...
- 阅读《大道至简第一章》读后感(java伪代码)
大道至简讲述的是软件工程实践者的思想,书的第一章引用了著名的----愚公移山这一历史故事,向我们讲述了编程的精义.汤问篇中所述的愚公移山这一事件,我们看到了原始需求的产生---“惩山北之塞,出入之迂” ...
- 十、oracle 常用函数
一.字符函数字符函数是oracle中最常用的函数,我们来看看有哪些字符函数:lower(char):将字符串转化为小写的格式.upper(char):将字符串转化为大写的格式.length(char) ...
- GitHub上有很多不错的iOS开源项目
GitHub上有很多不错的iOS开源项目,个人认为不错的,有这么几个:1. ReactiveCocoa:ReactiveCocoa/ReactiveCocoa · GitHub:GitHub自家的函数 ...
- HADOOP与ORACLE关联
安装Oracle和Oracle大数据连接器/OLH,尝试把HDFS中的数据文件装载到Oracle中的表 http://f.dataguru.cn/thread-460110-1-1.html 文档讲述 ...
- Chapter 2 Open Book——3
But when I walked into the cafeteria with Jessica — 但是当我和Jessica 一起走进自助餐厅的时候 trying to keep my eyes ...
- 【Machine Learning in Action --1】机器学习入门指南
摘自:http://www.jianshu.com/p/c3634a7f2320 机器学习算法 Coursera 上面 Stanford 的 机器学习 课程是优质的算法相关入门课程.Andrew Ng ...
- app调用支付宝支付 笔记
1.提交各种申请 2.通过后进入支付宝开放平台 --> 管理中心 -->创建应用 --> 填写相关信息 提交等待审核通过(1,2天) 3.下载集成包(https://doc. ...