HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20361 Accepted Submission(s): 7864
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
3
4
2
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.
再得到,m=10^(n*log10(n));
然后,对于10的整数次幂,第一位是1,
所以,第一位数取决于n*log10(n)的小数部分
1.令M = N^N
2.两边取对数,log10M = Nlog10N,得到M = 10^(Nlog10N)
3.令N^(N*log10N) = a(整数部分) + b(小数部分),所以M = 10^(a+b) = 10^a *10^b,由于10的整数次幂的最高位必定是1,所以M的最高位只需考虑10^b
4.最后对10^b取整,输出取整的这个数就行了。(因为0<=b<1,所以1<=10^b<=10对其取整,那么的到的就是一个个位,也就是所求的数)。
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
/*
m=n^n;两边同取对数,得到,log10(m)=n*log10(n);
再得到,m=10^(n*log10(n));
然后,对于10的整数次幂,第一位是1,
所以,第一位数取决于n*log10(n)的小数部分
*/
int t;
double x,y;
LL result;
cin>>t;
while(t--)
{
int n;
cin>>n;
x=n*log10(n);
y=(LL)x;
x=x-y;
result=(LL)pow(10.0,x);
cout<<result<<endl;
}
return ;
}
HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)的更多相关文章
- HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
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 Left-most Digit
传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1060 Leftmost Digit
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1060 Leftmost Digit (数学/大数)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 题解报告:hdu 1060 Leftmost Digit
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字. 输入 输入包含多个测试用例. ...
- HDU 1060 Leftmost Digit 基础数论
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10 ...
- HDU 1060 Leftmost Digit
基本思路:(参考大神和加自己的思考) 考虑到此题需要输入这么大的数a,并且还的求aa,求出来会更大,更多位.当时考虑用大数方法求(数组实现),结果实现不行.看网上大神采用对数法,巧妙避开处理这么大的数 ...
- HDU 1060 Leftmost Digit (数学log)
题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以 ...
随机推荐
- TOJ 3486 Divisibility
Description On the planet Zoop, numbers are represented in base 62, using the digits 0, 1, . . . , 9 ...
- 使用awstat分析Nginx的访问日志
在我的上一篇文章<使用 Nginx 提升网站访问速度>中介绍了 Nginx 这个 HTTP 服务器以及如何通过它来加速网站的访问速度.在实际的网站运营中,我们经常需要了解到网站的访问情况, ...
- php+editplus构建php调试环境
配置Editplus的PHP调试环境 1. php手册 1.1 打开Editplus进入菜单 [Tools] -> [Configure User Tools...]. 1.2 点击按钮 [Ad ...
- pat1006. Sign In and Sign Out (25)
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- linux机械磁盘服务器分区方案
/boot分区:用来存放与linux系统启动有关的程序,比如启动引导装载程序等,建议大小为100MB /usr分区:用来存放linux系统中的应用程序,其相关数据较多,建议大于3GB. /var分区: ...
- Caffe & Caffe2入门博客存档
caffe2 教程入门(python版) https://www.jianshu.com/p/5c0fd1c9fef9?from=timeline caffe入门学习 https://blog.csd ...
- C# 面试题二
1. 请编程实现一个冒泡排序算法? int [] array = new int [*] ; ; ; i < array.Length - ; i++) { ; j < ar ...
- 给string添加新的函数
var str = "abcdefg";String.prototype.constr = function(){ return this.split('').join('-'); ...
- Javascript 5种设计风格
1.过程式的程序设计 <script> /*Start and Stop animations using functions.*/ function startAnimation() { ...
- git获取别人远程dev分支上的代码
我们在使用 git clone xxx.git 下载代码的时候,获取到的只是 master上的代码 假入有个 dev 分支我们想获取上面的代码怎么办! #下载dev分支上的代码并切换到dev分支 g ...