HDU 1060
2012-09-04 22:06
183 查看
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8550 Accepted Submission(s): 3296
[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.
//x ^ x= 10^(x*lg(x))=10^(整数部分+小数部分) ;则x ^ x的最高位是由小数部分决定的(因为10的整数次幂不会影响最高位,只在最末位加0)。 //去掉整数部分(floor函数向下去整)得到10^(小数部分)最高位即是所求…… #include <iostream> #include <cmath> using namespace std; int main() { int i,j,k,T; double ans; int num; cin>>T; while(T--) { cin>>num; ans = log10((double)num); ans=ans-(int)ans; ans=ans*num; ans=ans-(int)ans; num=(int)pow(10.0,ans);//10的小于1的数次方肯定只有一位 cout<<num<<endl; } return 0; } //注意:涉及到数学函数最好g++提交,否则CE
相关文章推荐
- hdu 1060(思维)
- HDU 1060 Left-most Digit
- hdu 1060 Leftmost Digit
- hdu 1060(取前n位)
- HDU 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- HDU1060 数学方法实现超大数计算
- HDU 1060 Leftmost Digit
- hdu 1060
- hdu_1060_数学求解n^n的第一位数
- hdu——1060(数论之对数的使用)
- HDU 1060 Leftmost Digit(求n^n的最左位)
- hdu 1060——Leftmost Digit
- hdu 1060 数学
- hdu 1060 the leftmost digit 计算N^N最左面的一位数
- Leftmost Digit (HDU 1060)
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060
- HDU 1060 Leftmost Digit