传送门

Leftmost Digit

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

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
 
Solution
取对数。
设 n^n = x*10^y(n^n的科学计数法表示),
则 log (n^n) = y + log x
 
Implementation
#include <bits/stdc++.h>
using namespace std; int main(){
int T;
scanf("%d", &T);
for(int n; T--; ){
scanf("%d", &n);
double t=log10(n)*n;
printf("%d\n",(int)pow(, t-floor(t)));
}
}

Tips

<cmath>内常用函数:

pow

exp

log  自然对数

log10 常用对数

log2  以2为底的对数

floor

ceil

HDU 1060 Left-most Digit的更多相关文章

  1. 题解报告:hdu 1060 Leftmost Digit

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字. 输入 输入包含多个测试用例. ...

  2. HDU 1060 Leftmost Digit 基础数论

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060   这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10 ...

  3. HDU 1060  Leftmost Digit

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

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

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

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

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

  6. HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】

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

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

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

  8. HDU 1060 Leftmost Digit

    基本思路:(参考大神和加自己的思考) 考虑到此题需要输入这么大的数a,并且还的求aa,求出来会更大,更多位.当时考虑用大数方法求(数组实现),结果实现不行.看网上大神采用对数法,巧妙避开处理这么大的数 ...

  9. HDU 1060 Leftmost Digit (数学log)

    题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以 ...

随机推荐

  1. Jython概要

    1.安装jython 1.1 进入http://www.jython.org/downloads.html ,网页上会显示当前最稳定的版本(The most current stable releas ...

  2. 05Spring_Bean属性的集合类型的注入

  3. ssh scp 复制文件和文件夹

    三,复制文件或目录命令:  复制文件:  (1)将本地文件拷贝到远程  scp 文件名用户名@计算机IP或者计算机名称:远程路径 本地192.168.1.8客户端  scp /root/install ...

  4. Go 命令之 godep

    本文参考:http://www.cnblogs.com/me115/p/5528463.html#h20 http://studygolang.com/articles/4385 关于Godep 发现 ...

  5. 微软职位内部推荐-UX Designer II

    微软近期Open的职位: Search Technology Center Asia (STCA) Position: UX Designer Location: Beijing, China Sea ...

  6. SQLServer如何删除字段中的某个字符串,或者替换为空格?

    sql="update Table set 字段=REPLACE ( 字段,'123' , ' ') where XXX条件"把字段中123替换为空格

  7. JNDI全面总结(zz)

    原理:         在DataSource中事先建立多个数据库连接,保存在数据库连接池中.当程序访问数据库时,只用从连接池中取空闲状态的数据库连接即可,访问结束,销毁资源,数据库连接重新回到连接池 ...

  8. Qt opencv程序运行异常

    搭建了两次qt opencv vs ,经常出现程序运行异常.找了几个原因如下: 1.opencv的路径未配置或配置有误. 2.qt中pro文件包含不正确. 3.测试opencv程序不正确.如视频或图片 ...

  9. 使用Let’s Encrypt轻松配置https站点

    使用Let's Encrypt轻松配置https站点 https不仅能提高网站安全,更是被搜索引擎纳入排名的因素之一. 2015年10月份,微博上偶然看到Let's Encrypt 推出了beta版, ...

  10. 自编基于jQuery实现分页插件

    $(function(){ }); /** * @params dataUrl:请求数据url地址 * @params countUrl:请求数据总数url地址 * @params pageSize: ...