[置顶] hdu 1060 leftmost digit

链接: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;
    }
}


你可能感兴趣的:(ACM,HDU,OJ,digit,leftmost)