hdu1060 Leftmost Digit---求N的N次方的首位(对数)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1060
题目描述:
求N的N次方的第一位。
思路:
第一次做这种类型的题目,学到了如何运用对数。
首先推导下述公式


k的以10为底的对数值必定是A.B的形式,A为结果的整数部分,B为小数部分


这里求nn的首位只需要求出A.B = Nlog(N),然后取小数位即可,因为10A并没有什么用,只要算出100.B
就算出了首位数字。这种方法可以用来求前i位。(i数值要小,因为运算精度有限)
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int T, n, m, cases;
int main()
{
cin >> T;
while(T--)
{
cin >> n;
double s = 1.0 * n * log10(1.0 * n);
s -= (ll)s;
s = pow(, s);
while(s < )s *= ;
cout<<(int)(s)<<endl;
}
return ;
}
hdu1060 Leftmost Digit---求N的N次方的首位(对数)的更多相关文章
- HDU 1060 Left-most Digit
传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...
- HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Leftmost Digit(hdu1060)(数学题)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1060 Leftmost Digit (数论,快速幂)
Given a positive integer N, you should output the leftmost digit of N^N. InputThe input contains se ...
- Leftmost Digit
Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input ...
- Leftmost Digit(数学)
Description Given a positive integer N, you should output the leftmost digit of N^N. Input The inp ...
- HDU 1060 Leftmost Digit (数学/大数)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- HEX文件合并方法
通过开发嵌入式系统时,可能需要boot引导应用程序,一个小工程就需要两个hex文件进行合并,但是生产的时候都是裸片烧的,因此需要将两个合并为一个文件 以下是具体合并的方法: 1.确保自检安装了ultr ...
- 测试驱动开发实践2————从testList开始
内容指引 1.测试之前 2.改造dto层代码 3.改造dao层代码 4.改造service.impl层的list方法 5.通过testList驱动domain领域类的修改 一.测试之前 在" ...
- java错题集
解析:java中,JavaDoc注释以 /** 开头(中间写内容)以*/结尾 解析:A对象是类的实例,不是集合,其余正确 解析:创建一个对象的语法为: 类名 对象名=new 类名();,因此正确答案为 ...
- java基础笔记(4)----数组
介绍: 数组是一种数据类型,是引用类型,是一块连续的内存空间,用于存储和管理相同类型的多个数据. 定义:-- > 数组的声明方式 先声明,在开辟内存空间--> int [] a; a=ne ...
- 【数据结构】赫夫曼树的实现和模拟压缩(C++)
赫夫曼(Huffman)树,由发明它的人物命名,又称最优树,是一类带权路径最短的二叉树,主要用于数据压缩传输. 赫夫曼树的构造过程相对比较简单,要理解赫夫曼数,要先了解赫夫曼编码. 对一组出现频率不同 ...
- 关于伪类after后续追加,实现js事件(如点击事件)
实现情况为:点击"编辑"后,"编辑"文字变成"完成",再点击伪类元素后的"完成",此时的"完成"应该 ...
- Leetcode 17.——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Leetcode 14——Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings. 很简单的一个描述,最 ...
- MySQL之数据的insert-delete-update操作
主要是对数据的一些基本操作:增加.删除.修改
- Beta Scrum Day 3
听说