hdu 1060 Leftmost Digit
来源:互联网 发布:python中的iter 编辑:程序博客网 时间:2024/06/05 11:53
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12283 Accepted Submission(s): 4695
Problem Description
Given a positive integer N, you should output the leftmost digit of N^N.
Input
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).
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the leftmost digit of N^N.
Sample Input
234
Sample Output
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.
Author
Ignatius.L
Recommend
We have carefully selected several similar problems for you: 1061 1071 1573 1066 1065
数学题,求n的n次方结果中最左边的一位数
幸好前几天胜哥考了我一个问题:求n!的位数
解法是用log10(n!)==log10(n)+log10(n-1)+...+log10(1);
又遇到类似题我就很自然地想到了用log
不妨设x == log10(n^n) == n*log(n);
则10^x == n^n,就转化为求10的x次方最左边一位的值
这样只需取出x的小数部分即可
虽然一开始思路就是对的,但是CE了好多次,发现自己每次用log总是各种错,但是编译器又不报错。。。
代码如下:
#include <map>#include <cmath>#include <vector>#include <string>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#define esp 1e-9#define MAXN 10010#define ll long long#define INF 0x7FFFFFFF#define BUG system("pause")#define SW(a,b) a^=b;b^=a;a^=b;using namespace std;int main(void){ll t;double n;cin >> t;while(t--){cin >> n;if(n){double x = n*log10((double)n);ll ts = x;x -= ts;ll w = (ll)pow(10.0,x);cout << w << endl;}elsecout << "1" << endl;}return 0;}
0 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
- linux下svn常用指令
- Oracle Dedicated server 和 Shared server(专用模式 和 共享模式) 说明
- 持之以恒的学习心态才是真正学会互联网网站制作技能的上策
- openwrt使用sdk编译应用程序
- Java设计模式的六大原则
- hdu 1060 Leftmost Digit
- 如果选择合适的资源
- 区分 :字符指针变量和字符数组的区别和联系
- 第三周作业-循环与判断语句LoopExamle
- # ## #@
- 用两个栈实现一个队列——我作为面试官的小结
- ios sdk6.1 Link against the umbrella framework 'System.framework' instead.
- CloseHandle(),TerminateThread(),ExitThread()的区别
- 腾讯2012实习生笔试题+答案解析