Leftmost Digit

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

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.
 
//这题不难读懂,就是说 N^N 的最高位是什么数字,第一行 t 代表测试数据组数
显然这不是模拟能解决的n有10亿,那么就肯定是数学题了
   e = log10(N^N) = N * log10(N) (对数公式)
那么 10^e == N^N 然后想想 10^floor(e) 等于什么呢,不就是与 N^N 相同的位数,但最小的数吗?就是 1 后面都是 0 的数
而 floor( 10^(e-floor(e)) ) 就是就是要求的了
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std; int main()
{
int t;
int n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
double temp=n*log10(n*1.0);
double res=temp-floor(temp);
printf("%d\n",(int)pow(10.0,res));
}
return ;
}
 
 

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

  1. HDU 1060 Left-most Digit

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

  2. hdu acmsteps 2.1.8 Leftmost Digit

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

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

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

  4. Leftmost Digit

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

  5. HDU 1060  Leftmost Digit

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

  6. Leftmost Digit(数学)

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

  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. HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】

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

随机推荐

  1. Ubuntu14.04终端主机名+用户名修改配色方案

    首先打开终端:输入指令ls -a 然后输入指令:vi .bashrc 先按下字母A,进入编写: 在文档最后一行添加: PS1='${debian_chroot:+($debian_chroot)}\[ ...

  2. hadoop错误总结

    1.hadoop3: mkdir: cannot create directory `/usr/local/hadoop/bin/../logs': Permission denied 把所有Data ...

  3. python实现将文件夹内所有txt文件合并成一个文件

    新建一个文件夹命名为yuliao,把所有txt文件放进去就ok啦!注意路径中‘/’,windows下路径不是这样. #coding=utf-8  import os #获取目标文件夹的路径 filed ...

  4. 转: Servlet-jsp从入门到精通 1~5

    评注: 来自简书,内容很简要. http://www.jianshu.com/p/d718a5f4a850 (一) http://www.jianshu.com/p/06efc32c10cf   (二 ...

  5. 【原创】关于bug反正出现的问题可能

    bug修正的问题:1. xib问题.2. 模块不清同时修改.3. svn代码合并的修改熟悉程度.4. 禁止全局格式化代码.

  6. hdu 4512 吉哥系列故事——完美队形I(最长公共上升自序加强版)

    首先要去学习最长公共上升子序列LCIS.然后是对n*n效率的算法进行优化,这里要注意的是能够求出来的序列中间能够有一个最高的.刚開始将输入的数组进行逆置,写下来发现这可能存在问题. 只是详细是什么也没 ...

  7. Assets 读取assets中的文件

    res/raw和assets的相同点: 1.两者目录下的文件在打包后会原封不动的保存在apk包中,不会被编译成二进制. res/raw和assets的不同点:1.res/raw中的文件会被映射到R.j ...

  8. kali渗透综合靶机(一)--Lazysysadmin靶机

    kali渗透综合靶机(一)--Lazysysadmin靶机 Lazysysadmin靶机百度云下载链接:https://pan.baidu.com/s/1pTg38wf3oWQlKNUaT-s7qQ提 ...

  9. 谈谈PHP网站的防SQL注入

    SQL(Structured Query Language)即结构化查询语言.SQL 注入,就是把 SQL 命令插入到 Web 表单的输入域或页面请求参数的查询字符串中,在 Web表单向 Web 服务 ...

  10. JQuery DataTables学习

    1.Datatables简单介绍 DataTables是一个jQuery的表格插件.这是一个高度灵活的工具,根据的基础逐步增强,这将添加先进的互动控制.支持不论什么HTML表格. 主要特点: 自己主动 ...