Leftmost Digit

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

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
 
 //x ^ x= 10^(x*lg(x))=10^(整数部分+小数部分) ;则x ^ x的最高位是由小数部分决定的(因为10的整数次幂不会影响最高位,只在最末位加0)。
 //去掉整数部分(floor函数向下去整)得到10^(小数部分)最高位即是所求……
 //x ^ x= 10^(x*lg(x))=10^(整数部分+小数部分) ;
#include <stdio.h>
#include <math.h> int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,t;
double a;
scanf("%d",&n);
a = log10((double)n);
a -= (int)a;
//n*a的结果可能很大,所以先减去整数部分再乘
a = n*a;
t = (int)a;
a -= t;
t = (int)pow(10.0,a);
printf("%d\n",t);
}
return ;
}

链接:http://www.cnblogs.com/hxsyl/archive/2012/09/04/2671068.html

总结:数学题,log的运用,掌握的不行,需多练习

hdu_1060_Leftmost Digit_201311071827-2的更多相关文章

随机推荐

  1. CentOS Linux VPS桌面环境一键安装包

  2. Gym - 102059D 2018-2019 XIX Open Cup, Grand Prix of Korea D. Dumae 贪心+堆

    题面 题意:有3e5个人排成一列,然后Li,Ri表示每个人可以站在[Li,Ri]中的一个,然后M(1e6)个限制条件,某个人一定要在某个人前面,求一种合法方案,无解输出-1 题解:首先可以想到对于限制 ...

  3. SVD 学习笔记

    本文主要学习了这篇博客:http://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html,将SVD讲的恨透 ...

  4. 【知识总结】多项式全家桶(一)(NTT、加减乘除和求逆)

    我这种数学一窍不通的菜鸡终于开始学多项式全家桶了-- 必须要会的前置技能:FFT(不会?戳我:[知识总结]快速傅里叶变换(FFT)) 以下无特殊说明的情况下,多项式的长度指多项式最高次项的次数加\(1 ...

  5. [转]linux之磁盘配额(quota)

    转自:http://www.jb51.net/LINUXjishu/78446.html 磁盘配额(quota)比较常用的几个情况是: * 针对WWW server,例如:每个人的网页空间的容量限制 ...

  6. Unity学习-鼠标的常用操作(八)

    本次主要介绍5个鼠标事件 void OnMouseEnter():鼠标进入 void OnMouseExit():鼠标移出 void OnMouseDown():鼠标点击 void OnMouseUp ...

  7. 属性字符串(NSAttributedString)的简单应用

    属性字符串NSAttributedString 可以对字符串附加格式信息,由于对于对不同文本片段使用不同的格式,属性字符串类特别合适. IOS 6中对样式文本有了大改善,大部分主要的UIKit控件都允 ...

  8. Java 中 父类变量访问子类方法 需要使用 类型转换 (instenceof)关键字 /类型判断/

    通过数组元素访问方法的时候只能访问在 Animal中定义的方法,对 于 Tiger类和  Fish中定义的方法时却不能调用,例如语句  animal[2].swim();就是不正确的.当 需要访问这些 ...

  9. activity间传递参数

    传递值对象 值对象可以理解为自定义的数据类型对象. 为了完成这个知识点的讲解,先来创建一个User类型的类,它有name和age两个属性,然后请添加getter/setter方法,构造方法等基本方法. ...

  10. Jupyter(Ipython) Notebook 入门

    upyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 一般用来编写漂亮的交互式文档. 文学编程的读者不是机器,而是人. 我们 ...