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. 分布式消息系统Kafka初步(一) (赞)

    终于可以写kafka的文章了,Mina的相关文章我已经做了索引,在我的博客中置顶了,大家可以方便的找到.从这一篇开始分布式消息系统的入门. 在我们大量使用分布式数据库.分布式计算集群的时候,是否会遇到 ...

  2. Linux下安装Oracle的过程和涉及的知识点-系列6

    16.一路安装后.会提示下面界面.此时须要用root登录下面文件夹,然后运行这两个脚本. 至此,Oracle软件的安装就已经完毕了,接下来就能够创建数据库了. 17.选择自己定义数据库: 输入数据库名 ...

  3. 【BZOJ】【3671】【NOI2014】随机数生成器

    贪心 嗯……其实生成这个矩阵就是一个$O(n^2)$的模拟 = = 然后?字典序最小?贪心呗= =能选1就选1,然后能选2就选2…… 我们发现,对于矩阵(1,1)~(n,m),假设1的位置是(x,y) ...

  4. 数据库实例: STOREBOOK > 用户 > 编辑 用户: PUBLIC

    ylbtech-Oracle:数据库实例: STOREBOOK  >  用户  >  编辑 用户: PUBLIC 编辑 用户: PUBLIC 1. 一般信息返回顶部 1.1, 1.2, 2 ...

  5. 使用标准模板find函数来对结构体容器进行查找

    最近在写一个项目,项目中需要获得类下面的所有对象,所以我采用了map容器,以string为关键字,list容器为内容来进行查找,而list中是一些struct结构体.由于在插入操作的时候需要判断该对象 ...

  6. linked-list-random-node

    https://leetcode.com/problems/linked-list-random-node/ // Using Reservoir sampling algorithm // http ...

  7. jqGrid常用属性和方法介绍

    jqGrid API中文手册:http://blog.mn886.net/jqGrid/ 一.jqGrid属性: width:Grid的宽度,如果未设置,则宽度应为所有列宽的之和:如果设置了宽度,则每 ...

  8. 宿主机为linux、windows分别实现VMware三种方式上网(转)

    一.VMware三种方式工作原理1 Host-only连接方式  让虚机具有与宿主机不同的各自独立IP地址,但与宿主机位于不同网段,同时为宿主主机新增一个IP地址,且保证该IP地址与各虚机IP地址位于 ...

  9. 【Django】Django如何保证并发操作数据一致性问题

    代码示例: 使用 select for update 数据库查询 select ... for update 是数据库层面上专门用来解决并发取数据后再修改的场景的,主流的关系数据库 比如mysql.p ...

  10. IIS-网站发布之后访问HTTP 错误 403.14 - Forbidden

    这种问题一般是因为页面本身发生了错误的原因导致的,这个时候先开启[目录浏览]功能 开通目录浏览之后再重新访问,就能看到相应的错误了,再去进行相应的解决就可以了.