hdu 1060——Leftmost Digit
2012-06-20 21:07
239 查看
[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]
[align=left]Sample Output[/align]
[align=left]Author[/align]
Ignatius.L
水题,算是为数学题目开头吧
算法思想:
由于算的是 n^n 的第一位数,刚开始有点犯难,但是后来释然了, n^n = 10 ^ (log10(n^n)) = 10 ^ (n * log10(n))
然后我们可以观察到: n^n = 10 ^ (N + s) 其中,N 是一个整数 s 是一个小数。
好了,结果出来了
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.
[align=left]Author[/align]
Ignatius.L
水题,算是为数学题目开头吧
算法思想:
由于算的是 n^n 的第一位数,刚开始有点犯难,但是后来释然了, n^n = 10 ^ (log10(n^n)) = 10 ^ (n * log10(n))
然后我们可以观察到: n^n = 10 ^ (N + s) 其中,N 是一个整数 s 是一个小数。
好了,结果出来了
#include<iostream> #include<cmath> #include<cstdio> using namespace std; int main() { int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); double m=n*log10(n); m=m-(__int64)(m); m=pow(10.0,m); printf("%d\n",(int)(m)); } return 0; }
相关文章推荐
- 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
- HDU1060 Leftmost Digit (数学推导)
- HDU - 1060 Leftmost Digit (数学取对数)规律
- HDU 1060 Leftmost Digit
- Leftmost Digit HDU - 1060
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- HDU 1060 Leftmost Digit 数学题
- hdu 1060 Leftmost Digit
- Leftmost Digit HDU 1060
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit