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. 36.面板Ext.Panel使用

    转自:https://www.cnblogs.com/linjiqin/archive/2011/06/22/2086620.html 面板Ext.Panel使用 概要 1.Ext.Panel概述 2 ...

  2. compileSdkVersion, minSdkVersion 和 targetSdkVersion的选择(copy)

    英文原文:Picking your compileSdkVersion, minSdkVersion, and targetSdkVersion 作者:Ian Lake,Google Android ...

  3. Elasticsearch搜索常用API(利用Kibana来操作)

    上面我们已经介绍了Elasticsearch的一些基本操作,这篇文章属于进阶篇,我们一起来学习. 前面我们创建了sdb和user文档,现在我们来看如何查询user中所有的文档呢? GET /sdb/u ...

  4. HDU 1754 Java

    退役后学java... 裸线段树 //By SiriusRen import java.util.*; import java.math.*; public class Main{ public st ...

  5. Spring Cloud (10) Hystrix-监控面板

    Hystrix DashBoard 断路器是根据一段时间窗内的请求状况来判断并操作断路器的打开和关闭状态的.Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界 ...

  6. VS插件-Resharper

    最近代码因为Resharper出现了点问题,同事问我这个插件有什么用,下面就列几个最近常用的功能.其他功能后续慢慢更新 1.什么是Resharper ReSharper是一个JetBrains公司出品 ...

  7. BOM 标记

    BOM 是 Byte Order Mark 的简称,即字节序标记.用于标记文本流: 表示文本流的字节顺序,是小端序(little-endian)还是大端序(big-endian); 表示文本流是 Un ...

  8. Java中的overload(方法的覆写)

    方法覆写(overload)与方法的重载非常相似,它在 Java的继承中也有很重要的应用. 写程序可能会碰到下面的情况,在父类中已经实现的方法可能不够精确,不能满足子类 的需求.例如在前面的 Anim ...

  9. Combox两级联动会经常出现的错误

    例如: 当我们遇到这种情况:(下拉框的隐藏值和显示值皆为实体类进行绑定值时)下拉框的隐藏值并不能成功获取到. 我们就可以使用下面 的方案来解决 ok ,成功获取到隐藏值. 还有一个,附加解决方案:

  10. python--11、数据库及SQL基础

    常用命令记录 查看库中所有表的引擎 SHOW TABLE STATUS FROM `center_main_db`; 还有一个更简洁,查询cmol_system_db库所有表的存储引擎\ SELECT ...