Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 14696    Accepted Submission(s): 5660

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

description:求解N^N的最左边的数字。
解法:num=N^N,两边取对数可得num=10^(N*log10(N))。其中10的整数次方的最左边总是数字10的整数倍,而决定num最左边的因素为N*log10N的小数部分。由此可解!

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std; int main()
{
int t;
cin >> t;
while (t--)
{
long long int num;
cin >> num;
double num1 = num * log10( double (num));
long long int num2 = (long long int) num1;
double num3 = num1 - num2;
num = (long long int) pow(10,num3);
cout << num<< endl;
}
return 0;
}

做不出本题数学是硬伤啊!!。。。。

HDU--1060的更多相关文章

  1. 【hdu 1060】【求N^N最低位数字】

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

  2. HDU 1060 Leftmost Digit 基础数论

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060   这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10 ...

  3. 题解报告:hdu 1060 Leftmost Digit

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字. 输入 输入包含多个测试用例. ...

  4. HDU 1060 Left-most Digit

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

  5. HDU 1060 Leftmost Digit

    基本思路:(参考大神和加自己的思考) 考虑到此题需要输入这么大的数a,并且还的求aa,求出来会更大,更多位.当时考虑用大数方法求(数组实现),结果实现不行.看网上大神采用对数法,巧妙避开处理这么大的数 ...

  6. HDU 1060  Leftmost Digit

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

  7. HDU 1060 Leftmost Digit (数学log)

    题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以 ...

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

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

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

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

  10. 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. 完善chrome翻译插件ChaZD,支持有道智云api

    首先放上该项目的github地址:https://github.com/codethereforam/ChaZD 之前想找一个chrome支持划词翻译的插件,最终在知乎上看到了这个回答,推荐的是Cha ...

  2. openstack ocata版本简化安装

    Network Time Protocol (NTP) Controller Node apt install chrony Edit the /etc/chrony/chrony.conf 添加如下 ...

  3. Wamp环境搭建常见错误问题解决

    第一点.对于apache + php + mysql 的版本的正确选择 问题:网上有些教学视频已经很早了,然后很多人照着来,完全和视频里讲的一样,但是结果就是搭建不成功. 出现问题原因:三件套的版本选 ...

  4. OpenStack运维(二):OpenStack计算节点的故障和维护

    1.计划中的维护 举例:需要升级某一个计算节点的硬件配置,需要将计算节点上的虚拟机迁移后在对其进行操作,分为两种情况. 1.1 云系统使用了共享存储 a. 获取虚拟机列表:nova list --ho ...

  5. 闲来无事做了一个批处理的win10账号管理

    @echo off %1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe&q ...

  6. mkdir 命令详解

    rmdir  <man.linuxde.net> 作用: rmdir 命令用来创建目录,该命令创建由dirname 命名的目录.如果在目录名的前面没有添加任何路径名,则在当前目录下创建由d ...

  7. 初识QT

    前言:这是写给纯小白看的文章,大神可以自行绕道. QT的优势(摘自360百科): Qt支持下列操作系统: Microsoft Windows 95/98, Microsoft Windows NT, ...

  8. 根据图片的路径(绝对路径/相对路径都可以),生成base64的

    根据图片的路径(绝对路径/相对路径都可以),生成base64的 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  9. K:java中的hashCode和equals方法

      hashCode和equals方法是Object类的相关方法,而所有的类都是直接或间接的继承于Object类而存在的,为此,所有的类中都存在着hashCode和equals.通过翻看Object类 ...

  10. 【转】教你开发jQuery插件

    阅读目录 基本方法 支持链式调用 让插件接收参数 面向对象的插件开发 关于命名空间 关于变量定义及命名 压缩的好处 工具 GitHub Service Hook 原文:http://www.cnblo ...