HDU 1060 Leftmost Digit

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1060


取对数,然后求小数部分,然后求幂,ok


代码如下:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std;

const int N=1001;
typedef long long LL;

int main()
{
    int i,j,n,T;
    cin>>T;
    while(T--)
    {
        scanf("%d",&n);
        double t=n*log10(double(n));//取对数
        LL a=(LL)t;//整数部分表示位数-1
        t-=a;//小数部分
        t=pow(10.0,t);
        a=(LL)t;
        while(a==0)
        {
            t*=10;
            a=(LL)t;
        }
        printf("%d
",a);
    }

    return 0;
}


原文地址:https://www.cnblogs.com/dyllove98/p/3143132.html