日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

震惊! Leftmost Digit

發布時間:2025/3/12 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 震惊! 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的全部內容,希望文章能夠幫你解決所遇到的問題。

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