hdu 1060 Leftmost Digit
2016-03-24 16:19
489 查看
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15851 Accepted Submission(s): 6184
[align=left]Problem Description[/align]
Given a positive integer N, you should output the leftmost digit of N^N.
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each test case, you should output the leftmost digit of N^N.
[align=left]Sample Input[/align]
2
3
4
[align=left]Sample Output[/align]
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.
题意:输入n 输出n^n的结果的个位数
题解:将n^n用科学计数法表示为n^n=a*10^x (如274=2.74*10^2)将等式两边都取对数的lg n^n=lg(a*10^x)
n*lgn=lga+x*lg(10) == n*lgn=lga+x 所以lga=n*lgn-x 由指对互换得a=10^(n*lgn-x) x为n^n的位数减一,如1234 ==n^n则x=3 同样有指对互化得lg(n^n)=x可化为10^x=n^n,所以x为 lg(n^n)向下取整
#include<stdio.h> #include<string.h> #include<cstdio> #include<string> #include<math.h> #include<algorithm> #define LL long long #define PI atan(1.0)*4 #define DD double #define MAX 30000 #define mod 100 #define dian 1.000000011 #define INF 0x3f3f3f using namespace std; int main() { LL n,m,j,i,t,k; scanf("%lld",&t); DD sum; while(t--) { scanf("%lld",&n); sum=(long DD)n*log10(n); sum-=(LL)sum; k=pow(10,sum); printf("%lld\n",k); } return 0; }
相关文章推荐
- lucene 学习日记(一) 源码的导入,及第一个demo的开始
- 自定义msi安装包的执行过程
- AndroidStudio使用常见问题(实时更新)
- DDL语句--创建数据库
- 博客入驻阿里“云栖社区”
- MMC/SD/SDIO的区别
- git fetch的使用
- VR:下一个技术风口
- 使用NuGet加载包,发现加载的dll都是最新版,原来少加了参数[-Version]
- 用Jenkins配置自动化构建
- bzoj 2502 清理雪道(有源汇的上下界最小流)
- Java中的内部类和匿名类-----(java复习)
- 叶脊网络拓扑(leaf-spine)
- 解决touchend与内部元素冒泡问题 7fe0
- 华为2016实习生上机测试
- IO端口和IO内存
- list里面数据被覆盖
- [LeetCode][数论]Ugly Number
- CxImage的编译及简单使用举例
- 高效的找出两个List中的不同元素