ZOJ.2277 The Gate to Freedom【数论-海伦】 2015/09/16

本文探讨了解开通往自由之门的数学谜题,并通过代码实现了解答过程。主要内容包括理解问题背景,分析输入输出规则,采用数学方法计算左数位数字,最后使用编程技巧实现解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Gate to Freedom

Time Limit: 2 Seconds      Memory Limit: 32768 KB

Background

It is dark at night.
It is silence at night.
It is she in the dark.
It is she in the silence.

Then a light appeared. A huge gate came into our sights, called

The Gate to Freedom


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.


Author: JIANG, Yanyan

Source: JIANG, Yanyan's Contest #2


设n^n = x,两边同时取对数得n*log10(n) = log10(x),取y=n*log10(n),可知y的小数部分即为n^n最高位的对数。

#include<cstdio>
#include<cmath>

using namespace std;

int main(){
    long long n;
    while( ~scanf("%lld",&n) ){
        double ret = n*log10(n) - (int)(n*log10(n));
        ret = pow(10,ret);
        printf("%d\n",(int)ret);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值