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. Author
Ignatius.L

首先,暴力算是一定会超时的,而且这么大的数也存不下

这道题运用了取对数来缩小运算范围,

推导过程如下:

设M=N^N,则log10(M)=Nlog10(N);

所以M=10^(N
log10(N));

继续转化

令N=x10^y 例如:155555555=1.5555555510^8;

M=10(N*log10(x*10y)=10(N*(y+log10x))=10(Ny)log10x

so, 只要求出log10x即可

取整即可

HDOJ--ACMSteps--2.1.8--Leftmost Digit-(取对数,数学)的更多相关文章

  1. hdu acmsteps 2.1.8 Leftmost Digit

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

  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. Leftmost Digit

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

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

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

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

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

  7. HDU 1060  Leftmost Digit

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

  8. Leftmost Digit(数学)

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

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

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

  10. 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. Just do it!!!

    4月英语竞赛期中考试 5月初级程序员考试 6月英语四级考试 7月期末考试 加油吧年轻人!

  2. MVC view视图获取Html.RenderAction方式带来的参数

    通过Html.RenderAction这种方式传递的参数,在view视图中获取要使用viewContext上下文来获取:Html.ViewContext.RouteData.Values[" ...

  3. AVFoundation下的视频分帧处理

    // // ViewController.m // VideoFrame // // Created by wiseman on 16/1/27. // Copyright (c) 2016年 wis ...

  4. C++内存申请容易产生的错误

    1.起因 前两天用python写了一款工具用来把excel文件转换成json文件,今天给他们用的时候发现在文本下看正常,但是在程序中使用就是会多出一些莫名其妙的字符. 2. 调查 原来主要是我写的工具 ...

  5. gridControl 部分属性

    DEVexpress GridControl 属性设置 2013年11月22日 ⁄ 综合 ⁄ 共 18319字 ⁄ 字号 小 中 大 ⁄ 评论关闭 1. 如何解决单击记录整行选中的问题 View-&g ...

  6. Struts2--课程笔记1

    第一个Struts程序: 在开发Struts程序之前,首先要导入额外的jar包,基本需求的是14个jar包,关于14个ja包是什么,有什么作用,此处不讲述. 还要配置web.xml文件,注册Strut ...

  7. tomcat的几种配置方式(常用)

    https://www.baidu.com   url www.baidu.com 主机名 baidu.com 域名 第一种 放在webapp目录下 也可以放在ROOT 根目录下 访问路径 IP:端口 ...

  8. sublime3安装

    1.下载安装程序 http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%20Build%203059%20Setup.exe 2.下载注册机 http:/ ...

  9. mybatis------xml的一些规范等

    转与拼接: MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis 使用简单的 XML ...

  10. JavaScript高级程序设计:第二十章

    第二十章 一.语法 JSON的语法可以表示以下三种类型的值: (1)简单值 (2)对象 JSON的对象与javascript字面量有一些不同.例如,在javascript中,前面的对象字面量可以写成下 ...