前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ1060Leftmost Digit

HDUOJ1060Leftmost Digit

作者头像
Gxjun
发布2018-03-22 10:38:52
5770
发布2018-03-22 10:38:52
举报
文章被收录于专栏:mlmlml

Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11600    Accepted Submission(s): 4430

Problem Description

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.

Author

Ignatius.L

一个数n^n=p= x*10^m  所以log(p)=n*log10(n);

而这和我们要求的最高位i的那个数有什么关系乐 比如求1234的最高位为1,而log10(1234)=log10(1.234*10^3)=log10(1.234)+3;

而最高位即为其pow(10,1og10(1.234))=1.234的整数1;

=log10(n^n)=n*log10(n);所以同样的道理,就可以求这个了.....

代码:

 1 #include<stdio.h>
 2 #include<math.h>
 3 int main()
 4 {
 5     int n,m;
 6     scanf("%d",&m);
 7     while(m--)
 8     {
 9         scanf("%d",&n);
10         double a=n*log10(1.0*n);
11         a-=(__int64)a;
12         printf("%d\n",(int)pow(10,a));
13     }
14     return 0;
15 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-01-07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Leftmost Digit
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档