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. 洛谷P3690 【模板】Link Cut Tree (LCT)

    题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的xor ...

  2. C++练习 | 求解二叉树的高度

    int h(BTree *bt) { if(bt->lchild==NULL&&bt->rchild==NULL) ; if(bt->lchild!=NULL& ...

  3. List和ArrayList

    1.为什么List list = new ArrayList()? 也不是非常夸张的说,一定要用List代替ArrayList接收,只是说这样是良好的编码习惯,便于以后代码可能重构. 首先要明白接口和 ...

  4. js实现把textarea通过换行或者回车把多行数字分割成数组,并且去掉数组中空的值。

    删除数组指定的某个元素 var msg = " ";  //textarea  文本框输入的内容 var emp = [ ];   //定义一个数组,用来存msg分割好的内容 1. ...

  5. HTML5常用标签及特殊字符表

    *http://html5doctor.com/nav*http://html5doctor.com/article*http://html5doctor.com/section*http://htm ...

  6. 将http转为https访问

    1.去阿里云购买证书 有免费一年的证书 最多20个 一个证书需要填写一个二级域名 www.xxx.com2.开启apache相应配置 #修改httpd.conf文件 LoadModule ssl_mo ...

  7. Vue2.5入门-2

    todolist功能开发 代码 <!DOCTYPE html> <html> <head> <title>vue 入门</title> &l ...

  8. Go 入门 - 包,函数和变量

    主要内容来自中文版的官方教程Go语言之旅 目的为总结要点 包,函数和变量 包 import 语法,多个用括号换行扩起,包之间不需要间隔符,用引号引起 import ( "fmt" ...

  9. Docker CPU Usage

    背景 当一台机器上跑有多个 Docker Container 的时候,我们需要知道,哪些容器占用了多少资源.采集这些指标,来让我们可以更加好的分配资源给每个 Container. 获取容器CPU使用率 ...

  10. BFC与浮动

    一.BFC的含义 BFC(block formatting contexts) 块级元素格式化上下文,它决定了块级元素如何对它的内容进行布局,以及与其它元素的关系和相互作用. 块级元素:父级(是一个块 ...