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. 

题目意思:求n^n结果的第一位。
解题思路:我们可以将其看成幂指函数,那么我们对其处理也就顺其自然了,n^n = 10 ^ (log10(n^n)) = 10 ^ (n * log10(n)),
然后我们可以观察到: n^n = 10 ^ (N + s) 其中,N 是一个整数 s 是一个小数。由于10的任何整数次幂首位一定为1,所以首位只和s(小数部分)有关。
 #include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long int
using namespace std;
int main()
{
int t,n;
double m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
m=n*log10(n);
m=m-(ll)(m);
m=pow(10.0,m);
printf("%d\n",(int)(m));
}
return ;
}

Leftmost Digit(数学)的更多相关文章

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

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

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

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

  3. HDU 1060 Left-most Digit

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

  4. hdu acmsteps 2.1.8 Leftmost Digit

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

  5. Leftmost Digit

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

  6. HDU 1060  Leftmost Digit

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

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

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

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

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

  9. Leftmost Digit(hdu1060)(数学题)

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

随机推荐

  1. mysql5.7 安装版 表不能输入汉字解决方案

    安装版本 的安装目录没有 my.ini 配置文件 在所在表执行 alter table 数据表名 CONVERT TO CHARACTER SET utf8;

  2. P1015 回文数解题思路(非原创)

    测试 #include<bits/stdc++.h> using namespace std; int n,m,step; string nn; int len,nex; bool dfs ...

  3. vue+element 页面输入框--回车导致页面刷新的问题

    el-form 后面加上 @submit.native.prevent

  4. css之层叠上下文和层叠顺序

    大家在写网页的时候会不会经常遇到莫名奇妙的样式问题,比如谁覆盖了谁.也找不出原因,为什么z-index高的却没有覆盖掉z-index低的元素呢? 带着这些疑问.我做了个小实验.代码如下: <st ...

  5. Spring AOP代理模式

    代理模式 代理模式是一种设计模式,提供了对目标对象的另外的访问方式.即通过代理访问目标对象. 好处:可以再目标对象实现的基础上,增加额外的功能的操作.扩展目标对象的功能,而不改变现有的功能逻辑. 1. ...

  6. Centos7前后台运行jar包

    方式一: java -jar lf-test-1.0-SNAPSHOT.jar 前台运行,当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出. 方式二: java -ja ...

  7. #define定义数据溢出的问题

    使用合泰单片机做一个小东西,使用 #define TIMER_COUNT (30*60*1000) 时,发现结果老是不对,后来想想,是不是数据溢出了,一查果然是这样.看来是stm32用多了,总以为#d ...

  8. 柴柴随笔第三篇:安装虚拟机以及Linux基础入门

    虚拟机的安装 老师提供的作业指南给了我莫大的帮助,一步一步按着其中操作提示和网址链接,我首先下好了VM,也创建好了自己的第一台虚拟机. 接着按照步骤安装了Ubuntu到我的虚拟机. 到此,一切都顺风顺 ...

  9. 20155318 2016-2017-2 《Java程序设计》第三周学习总结

    20155318 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 一.类与对象 Clothes c1 = new Clothes();将c1名称参考至新建对象 ...

  10. 我与虚拟机的初次接触及初探Liux命令 20155338

    初识虚拟机及学习Linux命令的些许收获 虚拟机的安装 这个假期算是第一次正式的接触了虚拟机,以前在平时生活中也有听到过,但是真正自己动手安装虚拟机却是第一次,确实是既紧张又兴奋. 我是依据老师所发的 ...