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. vue+element 点击按钮后 导致 刷新页面 致url中拼接 ? 或者拼接参数

    https://blog.csdn.net/sinat_37255207/article/details/88917162 element 自己的<el-form></el-form ...

  2. 纯 js 实现上传文件支持拖拽

    开发「bufpay.com 个人即时到账收款平台」 后台需要支持开发者的微信和支付宝二维码上传. <p> <button class="btn btn-primary&qu ...

  3. CH4402 小Z的袜子(莫队)

    描述 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命-- 具体来说,小Z把这N只袜子从1到N编号, ...

  4. 查询优化百万条数据量的MySQL表

    转自https://www.cnblogs.com/llzhang123/p/9239682.html 1.两种查询引擎查询速度(myIsam 引擎 ) InnoDB 中不保存表的具体行数,也就是说, ...

  5. CentOS6安装各种大数据软件 第二章:Linux各个软件启动命令

    相关文章链接 CentOS6安装各种大数据软件 第一章:各个软件版本介绍 CentOS6安装各种大数据软件 第二章:Linux各个软件启动命令 CentOS6安装各种大数据软件 第三章:Linux基础 ...

  6. python教程(三)·函数进阶(上)

    在介绍了函数定义的方法后,再来介绍一些进阶知识 参数收集 有时候我们需要参数的数量是任意的,比如print函数的参数的数量是任意的,print函数的内部实现我们不探究,但是单单是参数数量可变这一方面实 ...

  7. CVE-2018-8174 EXP 0day python

    usage: CVE-2018-8174.py [-h] -u URL -o OUTPUT [-i IP] [-p PORT] Exploit for CVE-2018-8174 optional a ...

  8. C++中的函数

    1.函数的定义和调用 函数的定义形式 返回类型 函数名(形式参数) { 语句序列: } 函数的调用 调用:声明函数原型,函数调用 声明函数原型:类型说明符 被调函数名(含类型说明的形参表) 函数调用: ...

  9. 复数 一级ADT实现

    COMPLEX.h /* typedef struct { float RE; //实部 float IM; //虚部 }Complex; */ typedef struct complex * Co ...

  10. jquery ajax实例教程和一些高级用法

    jquery ajax的调用方式:jquery.ajax(url,[settings]),jquery ajax常用参数:红色标记参数几乎每个ajax请求都会用到这几个参数,本文将介绍更多jquery ...