The Gate to Freedom (数学思维题)

ZOJ Problem Set - 2277
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=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

给你一个N,求N^N第一位数字是几。

这个题用lg10写。
比如5 = 10lg5

首先:这个题可以换成所以 N^N = 10N*lgN

其次:比如108.3 = 108 * 100.3, 108第一位就是1,所以第一位数是几取决于 100.3,算这个 100.3就行了。

代码如下:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    double n;
    while(scanf("%lf",&n)!=EOF)
    {
      double a = n*(log10(n));    如果对应上边那个例子,这个a = 5.8;
      ll b = (n*log10(n));                                b = 5;
      int x = (int)pow(10, a-b);                          10^0.8 就是结果了
      printf("%d\n",x);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值