HDU 1060 Leftmost Digit
来源:互联网 发布:海关数据开发客户 编辑:程序博客网 时间:2024/06/08 17:29
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15759 Accepted Submission(s): 6137
Problem DescriptionGiven a positive integer N, you should output the leftmost digit of N^N.
InputThe 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).
OutputFor each test case, you should output the leftmost digit of N^N.
Sample Input234
Sample Output22HintIn 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.
这道题运用的是数学方法。假设S=n^n。两边同时取对数,得到lgS=nlgn。即有S=10^(nlgn)。把nlgn看做一个整体,假设它是由整数加上介于0到1之间的小数相加得到的。那么整数部分就不考虑了,就单纯的放大倍数而已。取决于小数部分。小数部分=nlgn-(__int64)nlgn。注意是__int64。因为小数部分在0到1之间,所以10得次方得到的数必定大于等于1且小于10。所以再对得到的数取整即可。即(int)pow(10,小数部分)。源代码:<span style="font-size:18px;">#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string>#include<string.h>#include<math.h>#include<map>#include<vector>#include<algorithm>using namespace std;#define MAX 0x3f3f3f3f#define MIN -0x3f3f3f3f#define N 1005int main(){int T;__int64 num;double temp1;double temp2;scanf("%d", &T);while (T--){scanf("%lld", &num);temp1 = num*1.0*log10(num*1.0);temp2 = temp1 - (__int64)temp1;printf("%d\n", (int)pow(10, temp2));}return 0;}</span>
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).
234
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.
<span style="font-size:18px;">#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string>#include<string.h>#include<math.h>#include<map>#include<vector>#include<algorithm>using namespace std;#define MAX 0x3f3f3f3f#define MIN -0x3f3f3f3f#define N 1005int main(){int T;__int64 num;double temp1;double temp2;scanf("%d", &T);while (T--){scanf("%lld", &num);temp1 = num*1.0*log10(num*1.0);temp2 = temp1 - (__int64)temp1;printf("%d\n", (int)pow(10, temp2));}return 0;}</span>
1 0
- HDU 1060 Leftmost Digit & BIT1046 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 LeftMost Digit
- HDU 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu - 1060 - Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- HDU-1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- bzoj 4035: [HAOI2015]T3 SG函数
- 框架
- BZOJ1057: [ZJOI2007]棋盘制作
- java.lang.ClassNotFoundException: Class bytes found but defineClass()failed
- C语言头文件的作用
- HDU 1060 Leftmost Digit
- spark1.5 编译错误整理
- ios优化的25条建议和技巧
- stackoverflow(翻译Serializable)
- int,long,long long,__int64数据类型的取值范围
- STC15W4K32S系列 低速模式
- Linux查看平均负载[cat /proc/loadavg]
- Android自定义view-打造酷炫的字体滑动高亮控件
- 推荐 git community book 中文版