Leftmost Digit

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

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.
 
//这题不难读懂,就是说 N^N 的最高位是什么数字,第一行 t 代表测试数据组数
显然这不是模拟能解决的n有10亿,那么就肯定是数学题了
   e = log10(N^N) = N * log10(N) (对数公式)
那么 10^e == N^N 然后想想 10^floor(e) 等于什么呢,不就是与 N^N 相同的位数,但最小的数吗?就是 1 后面都是 0 的数
而 floor( 10^(e-floor(e)) ) 就是就是要求的了
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std; int main()
{
int t;
int n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
double temp=n*log10(n*1.0);
double res=temp-floor(temp);
printf("%d\n",(int)pow(10.0,res));
}
return ;
}
 
 

Leftmost Digit(hdu1060)(数学题)的更多相关文章

  1. HDU 1060 Left-most Digit

    传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. hdu acmsteps 2.1.8 Leftmost Digit

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

  3. <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字

    1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...

  4. Leftmost Digit

    Problem Description Given a positive integer N, you should output the leftmost digit of N^N.   Input ...

  5. HDU 1060  Leftmost Digit

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

  6. Leftmost Digit(数学)

    Description Given a positive integer N, you should output the leftmost digit of N^N.   Input The inp ...

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

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

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

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

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

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

随机推荐

  1. BindDepthStencilState

    nx sdk里面有这么一个接口 真坑 对于stencil fun op有两组值分别对应front back face 现在调用这个接口只能设置back 不能设置front跟了memory 有段全是0把 ...

  2. python git log

    # -*- coding: utf-8 -*- # created by vince67 Feb.2014 # nuovince@gmail.com   import re import os imp ...

  3. POJ 2503-Babelfish(map)

    题目地址:POJ 2503 题意:输入一个字典.字典格式为"英语 外语"的一一映射关系然后输入若干个外语单词.输出他们的 英语翻译单词,假设字典中不存在这个单词,则输出" ...

  4. ARM指令中的函数调用

    1. 重要寄存器 SP 栈指针,  每一种异常模式都有其自己独立的r13,它通常指向异常模式所专用的堆栈,也就是说五种异常模式.非异常模式(用户模式和系统模式),都有各自独立的堆栈,用不同的堆栈指针来 ...

  5. Efficiently traversing InnoDB B+Trees with the page directory--slot

    Efficientlytraversing InnoDB B+Trees with the page directory 1.the purpose of the page directory As ...

  6. iOS实录:GCD使用小结(一)

    导语:在iOS中,多线程方案有四种:pthread.NSThread.NSOperation & NSOperationQueue 和 GCD,但是开发中GCD使用得最多,本文主要总结一下我使 ...

  7. python实现大文件分割与合并

    小U盘传大电影时可以免去用winrar分割文件时的压缩和解压缩过程. file.py import sys from os.path import exists fileCount = 0 def s ...

  8. S2:外观模式 Facade

    为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 什么时候使用:1,开发阶段,子系统越来越复杂,增加外观模式提供一个简单的调用接口.2,维护一个大 ...

  9. LeetCode题目:Minimum Path Sum

    原题地址:https://leetcode.com/problems/minimum-path-sum/ 大意:给出一个二维数组(int类型),求出从左上角到右下角最短的路径. 解决方法:动态规划 c ...

  10. UVA - 434 Matty&#39;s Blocks

    题意:给你正视和側视图,求最多多少个,最少多少个 思路:贪心的思想.求最少的时候:由于能够想象着移动,尽量让两个视图的重叠.所以我们统计每一个视图不同高度的个数.然后计算.至于的话.就是每次拿正视图的 ...