Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1982 Accepted Submission(s): 884

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.
 
 
 
   1:  #include<iostream>
   2:  #include<cmath>
   3:  using namespace std;
   4:  int main(){
   5:      int t;
   6:      unsigned long long n;
   7:      cin>>t;
   8:      while(t--){
   9:          cin>>n;
  10:          long double x=n*log10(n*1.0);
  11:          x-=unsigned long long int(x);
  12:          int ans=pow(10.0,double(x));
  13:          cout<<ans<<'\n';
  14:      }
  15:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

解释:

对一个数num可写为 number=10n * a,  即科学计数法,使a的整数部分即为num的最高位数字
       numbernumber=10n * a  这里的n与上面的n不等
       两边取对数: number*log10(number) = n + log10(a);
       因为a<10,所以0<log10(a)<1
       令x=n+log10(a); 则n为x的整数部分,log10(a)为x的小数部分
       又x=number*log10(number);
        a=10(x-n) =  10(x-int(x)))
        再取a的整数部分即得number的最高位.

hdu acmsteps 2.1.8 Leftmost Digit的更多相关文章

  1. HDU 1060 Left-most Digit

    传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字

    1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...

  3. HDU 1060  Leftmost Digit

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. HDU 1060 Leftmost Digit (数论,快速幂)

    Given a positive integer N, you should output the leftmost digit of N^N.  InputThe input contains se ...

  6. HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. HDU 1060 Leftmost Digit (数学/大数)

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. HDU ACM-Steps

    HDU ACM-Steps RECORD Chapter 1 Section 1 暖手题 1.1.1 A+B for Input-Output Practice (I) #include <st ...

  9. Leftmost Digit

    Problem Description Given a positive integer N, you should output the leftmost digit of N^N.   Input ...

随机推荐

  1. mysql-advanced-5.6.23-linux-glibc2.5-x86_64安装

    0,二进制安装: mysql-advanced-5.6.23-linux-glibc2.5-x86_64.zip   1,软件包 mysql-advanced-5.6.23-linux-glibc2. ...

  2. Unity小知识

    这些是我在开发时遇到的一些问题: 2D的碰撞器和3D的碰撞器是没有任何物理反应的,必须是2D对2D,3D对3D 碰撞器Collision包含触发物体的速度等信息,触发器没有

  3. php基础02:变量

    1.创建变量 <?php $num1 = 15; $num2 = 15.5; echo $num1+$num2; echo "<br>"; ?> 2.Loc ...

  4. RequiredFieldValidator 根据group组来触发验证

    今天在开发过程中遇到了这样一个问题 在这个用户添加界面中,我使用了多个验证控件RequiredFieldValidator,分别控制用户名密码.在默认情况下,当单击“检查用户名”时,密码的验证控件也被 ...

  5. Android完美禁用Home键

    重写Activity的onAttachedToWindow 方法 @Override public void onAttachedToWindow() { System.out.println(&qu ...

  6. JS模拟Alert与Confirm对话框

    这2个例子都是用原生JS写的,主要是用JS拼接了界面,并未做过多的事件监听.,样式用了Css3的一些特性. 调用方式则为: //Alert Alert.show('我警告你哦~'); //Confir ...

  7. Openwrt Uboot烧写

    Openwrt 烧uboot 需要慎重,一般买一个带不死uboot的路由器再折腾会比较安全,因为 openwrt firmware对uboot分区进行了保护,而且带有不死uboot的路由器可以通过we ...

  8. 网页音乐突破金币(RMB)下载限制

    我平时有时间会跳跳舞 跳舞肯定要有音乐呀 于是在网上找音乐 好不容易找到了一个网站,里面有很多很全的音乐 正准备下载呢,尼玛居然要金币! 在这里解释一下,金币你可以通过回复帖子或者发帖子得到,但是数量 ...

  9. Orchard常见问题

    本文链接:http://www.cnblogs.com/souther/p/4543299.html 什么是Orchard Orchard是一个免费,开源,注重社区的项目,其目标是提供ASP.NET平 ...

  10. C++读取特定路径下文件目录及文件名称

    这几天在弄一个项目,需要读取给定路径下的所有文件夹名称或所有带后缀的文件名. 查了下C++的资料,发现有很多方法,这里总结其中的一种,其他用法类似. 主要用到了以下几个头文件(类):io.h, fst ...