题解: The Gate to Freedom(ZOJ-2277)

Problem

There’re some words on the gate: “This gate will lead you to freedom. First, you have to open it. I have a problem for you to solve, if you answer it correctly, the gate will open!”

“Tell me, young boy, what is the leftmost digit of N^N?”

Input

This problem contains multiple test cases.

Each test case contains an integer N (N<=1,000,000,000).

Output

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

Sample Input

3
4

Sample Output

2
2

Contest: A Great Beloved and My Gate to Freedom
There is a cx, there is a love_cx.
题意:让你求n^n的最高位;
题解:因为y=x^x该函数是爆炸性增长,而且题目给的范围还特别大,所以我们应该用log10这个函数;
因为 NN=10N*lgN然而比方说指数位置为3.5,那么该函数的最高位就取决于100.5;因此我们只需要把100.5算出来就好了,AC代码如下;

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
string str1;
int main()
{
    double n;
    while(~scanf("%lf",&n))
    {
        double a=n*log10(n);//相当于10^3.5
        long long b=(n*log10(n));//相当于10^3;
        double c=pow(10,a-b);
        c=floor(c);
        printf("%.0lf\n",c);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值