日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

震惊! Leftmost Digit

發布時間:2025/3/12 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 震惊! Leftmost Digit 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目

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

Hint

In the first case, 3 * 3 * 3 = 27, so the leftmost digit is 2.
In the second case, 4 * 4 * 4 * 4 = 256, so the leftmost digit is 2.

分析:

對一個數num可寫為 num=a*10^n , 即科學計數法,使a的整數部分即為num的最高位數字
k^k=a*10^n
如何求a的值?
a=k^k/10^n
如何求n的值?
把n提出來,lga=k*lgk-n
n是整數,而且0 < k* lgk-n< 1, 這說明n是k * lgk的整數部分,因此n=(int)k*lgk
因此a=10^(k*lgk-(int)k *lgk)
實際上,由于k*lgk小數點后有許多數,而int 只有32 位,那么取整用(long long)

代碼

#include<stdio.h> #include<math.h> int main(){int n;double x,a;scanf("%d",&n);while(n--){scanf("%lf",&a);x=a*log10(a);printf("%d\n",(int)pow(10.0,x-(long long)x));} }

總結

以上是生活随笔為你收集整理的震惊! Leftmost Digit的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。