HDUOJ 1060 Leftmost Digit(求最左位公式)
来源:互联网 发布:协和怎么挂号 知乎 编辑:程序博客网 时间:2024/06/05 19:48
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15967 Accepted Submission(s): 6242
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: 1018 1061 1071 1573 1066
题解:
计算出N^N最左边的数,就是最高位的数。
设N^N=d.xxxxx * 10^(k-1),其中k表示N^N的位数,那么d.xxxxx=10^lg(N^N-(k+1)),再对d.xxxx取整即可获得最终结果。因为k等于lgN^N的整数部分加一,即k=lgN^N+1(取整),所以d=10^(lgN^N-lg10N^N)(取整)。
AC代码:
#include<iostream>#include<cmath>using namespace std;int main(){int t,N;double x=0.0;cin>>t;while(t--){cin>>N;x=N*log10((double)N);x-=(long long)x;x=(int)pow(10,x);cout<<x<<endl;}return 0;}
1 0
- HDUOJ 1060 Leftmost Digit(求最左位公式)
- HDUOJ 1160 Leftmost Digit
- Leftmost Digit (HDU 1060)
- Leftmost Digit(HDU 1060)
- HDU 1060 Leftmost Digit & BIT1046 Leftmost Digit
- hdu 1060 Leftmost Digit(数学题)
- HDOJ 题目1060Leftmost Digit(数学)
- HDU 1060 Leftmost Digit (数论)
- HDU 1060 Leftmost Digit(数论)
- HDU 1060 Leftmost Digit(数论)
- hdoj--1060--Leftmost Digit(数学)
- HDU 1060 Leftmost Digit(大数问题)
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- HDOJ 1060 Leftmost Digit
- 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- zzuli 1728: 社交网络(求期望值)
- java泛型方法的使用
- Storm 1.0.0 稳定版发布
- 栈和堆的区别
- 最小生成树
- HDUOJ 1060 Leftmost Digit(求最左位公式)
- NSPredicate谓词
- java泛型
- flume简介
- Android实现通过浏览器点击链接打开本地应用(APP)并拿到浏览器传递的数据
- iOS 基于 MVC 的项目重构总结
- NOI历年总结
- 获取最新iOS系统最新分布(官方)
- 仿照iphone设置点击更多显示全部内容