HOJ Leftmost Digit
来源:互联网 发布:java获取select的值 编辑:程序博客网 时间:2024/05/19 06:16
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=11
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3530 Accepted Submission(s): 1568Problem 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
把一个数字表示成科学计数法,用科学计数法求最高位。
n^n=m;
nlgn=lg(a*10^b) 1<=a<10
nlgn=lga+b
lga 为nlgn小数部分,b为nlgn整数部分
lga=nlgn-(long long)(nlgn)
#include <iostream>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <algorithm>#include <vector>#include <string>#include <cstring>#include <sstream>using namespace std;long long n;int main(){ int T; scanf("%d",&T); while(T--) { scanf("%I64d",&n); double tmp=n*1.0*log10(n)-(long long )(n*1.0*log10(n)); double t1=pow(10,tmp); double ans=floor(t1); printf("%.0f\n",ans); } return 0;}
0 0
- HOJ Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Android M App Permissions
- bzoj 3239: Discrete Logging (BSGS)
- poj 3026 Borg Maze dfs+prim
- LeetCode387 First Unique Character in a String
- 64 位应用中用什么替代 "int 3" 指令?
- HOJ Leftmost Digit
- 蓝桥杯 算法提高 算法提高 最大乘积
- Mybatis 中的<![CDATA[ ]]>
- 贪心 HDU 2037题解
- 2016年前端技术观察
- struts2项目向springmvc迁移 之 把项目跑起来
- 初步使用Arduino
- spring文档怎么读
- k-mean控卫聚类分析