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,两边取以 ...
随机推荐
- adb调试安卓
http://blog.csdn.net/liushida00/article/details/49797239
- C#(Winform)的SaveFileDialog(文件保存对话框)控件使用
#region 保存对话框 private void ShowSaveFileDialog() { //string localFilePath, fileNameExt ...
- 命令行编译java项目
命令行编译java项目 项目名: testproj 目录 src -> cn -> busix -> test bin lib 编译项目 cd testproj javac -d . ...
- BJFU 1551 ——delightful world——————【暴搜】
delightful world 时间限制(C/C++):20000MS/30000MS 运行内存限制:65536KByte总提交:33 测试通过:10 描述 ...
- FZU 2221—— RunningMan——————【线性规划】
Problem 2221 RunningMan Accept: 17 Submit: 52Time Limit: 1000 mSec Memory Limit : 32768 KB P ...
- PHP SECURITY CALENDAR 2017 学习总结-更新中
这篇文章主要以审计代码为主来分析每道题目中所存在的漏洞点,记录一下自己的学习: 1.Day 1 - Wish List class Challenge { const UPLOAD_DIRECTORY ...
- 《Python编程从入门到实践》_第二章_变量和简单数据类型
什么是变量 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Python ...
- 使用新浪API生成短连接
公司最近需要进行短信推广,需要发送大批量带有连接地址的短信给用户,并且需要统计短信的点击量.因为需要考虑短信成本问题,需要将长连接地址生成比较短的连接.因为公司本身没有短的一级域名,所以考虑到使用第三 ...
- JavaScript获取url参数
声明:以下内容转自网络 方法一 String.prototype.getUrlString = function(name) { var reg = new RegExp("(^|& ...
- 洛谷P2312 解方程(暴力)
题意 题目链接 Sol 出这种题会被婊死的吧... 首先不难想到暴力判断,然后发现连读入都是个问题. 对于\(a[i]\)取模之后再判断就行了.注意判断可能会出现误差,可以多找几个模数 #includ ...