Leftmost Digit

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

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
 
一个数n^n=p= x*10^m  所以log(p)=n*log10(n);
而这和我们要求的最高位i的那个数有什么关系乐 比如求1234的最高位为1,而log10(1234)=log10(1.234*10^3)=log10(1.234)+3;
而最高位即为其pow(10,1og10(1.234))=1.234的整数1;
=log10(n^n)=n*log10(n);所以同样的道理,就可以求这个了.....
代码:

 #include<stdio.h>
#include<math.h>
int main()
{
int n,m;
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
double a=n*log10(1.0*n);
a-=(__int64)a;
printf("%d\n",(int)pow(,a));
}
return ;
}

HDUOJ1060Leftmost Digit的更多相关文章

  1. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  2. [LeetCode] Number of Digit One 数字1的个数

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  3. [Leetcode] Number of Digit Ones

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  4. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  5. kaggle实战记录 =>Digit Recognizer

    date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...

  6. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  7. Last non-zero Digit in N!(阶乘最后非0位)

    Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  8. POJ3187Backward Digit Sums[杨辉三角]

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6350   Accepted: 36 ...

  9. Number of Digit One

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

随机推荐

  1. flume 日志导入elasticsearch

    Flume配置 . flume生成的数据结构 <span style="font-size:18px;">"_index" : "logs ...

  2. water-and-jug-problem

    以下这个解法也是参考了一些讨论: https://leetcode.com/discuss/110235/c-solution-using-euclidean-algorithm 还有这个解释原理的, ...

  3. 【计算机网络】详解网络层(二)ARP和RARP

    ARP ARP(Address Resolution Protocol,地址解析协议)是将IP地址解析为以太网MAC地址(物理地址)的协议.在局域网中,当主机或其他网络设备有数据要发送给另一个主机或设 ...

  4. 系统出现bootmgr is missing解决方式,戴尔dellserver装系统须要特别注意的问题

    系统出现bootmgr is missing解决方式,戴尔dellserver装系统须要特别注意的问题 欢迎关注http://blog.csdn.net/aaa123524457 转载请注明出处: h ...

  5. 游戏服务器框架:Leaf/go

    Leaf 是一个使用 Go 语言开发的开源游戏服务器框架,注重运行效率并追求极致的开发效率.Leaf 适用于几乎所有的游戏类型.其主要的特性: 良好的使用体验.Leaf 总是尽可能的提供简洁和易用的接 ...

  6. Spark+Kafka的Direct方式将偏移量发送到Zookeeper实现(转)

    原文链接:Spark+Kafka的Direct方式将偏移量发送到Zookeeper实现 Apache Spark 1.3.0引入了Direct API,利用Kafka的低层次API从Kafka集群中读 ...

  7. ListView 拖拽

    private void ListView1_MouseMove(object sender, MouseEventArgs e) { Patientappointment appointment = ...

  8. 转: 网卡名字eth0,eth1的修改方法

    转自:http://longwind.blog.51cto.com/419072/982738 我使用这个方法生效: 现象:只有eth2,    vi /etc/udev/rules.d/70-per ...

  9. [Backbone]5. Model & View, toggle between Models and Views -- 2

    Dr. Goodparts is pretty flaky and has been cancelling a lot of appointments lately. He's asked for a ...

  10. Android menu+ anctionbar

    一.概述 Menu,简单来理解就是当你按下手机的"menu"键时所弹出来的窗体,它被广泛应用着,差点儿在每一个应用中都有它的身影. 二.要求 用两种方式实现菜单功能. 三.实现 新 ...