您的位置:首页 > 其它

hdu 1060 leftmost digit

2015-10-30 00:09 417 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060

思路:nlogn的第一位小数位取出来,再求10的密就是我们要的结果了,不解释,就是这么叼。

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).

 

Output

For each test case, you should output the leftmost digit of N^N.

 

Sample Input

2
3
4

 

Sample Output

2
2

#include <iostream>
#include <cmath>
using namespace std;

int main(){
long double x;
int n;
cin>>n;
while(n--){
cin>>x;
long double xx = log10((long double)x);
xx *= x;
long double bit = xx - (long long)xx;
x = pow(10 , bit);
cout<<(int)x<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hdu acm oj leftmost digit