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 ...
随机推荐
- vs调试正确显示utf8格式字符串
自从将visual studio从2010升级到2015后,发现调用接口的utf8格式字符串不能正常显示了,常常被莫名其妙截断,查了下,原来可以直接将变量拖到watch窗口中,在变量名后面手动添加,s ...
- 1833 深坑 TLE 求解
题目描述: 大家知道,给出正整数n,则1到n这n个数可以构成n!种排列,把这些排列按照从小到大的顺序(字典顺序)列出,如n=3时,列出1 2 3,1 3 2,2 1 3,2 3 1,3 1 2,3 2 ...
- Linux下mysql的常用操作
Linux下mysql的常用操作: 显示数据库 show databases; 选择数据库 use 数据库名; 显示数据库中的表 show tables; 显示数据表的结构 describe 表名; ...
- 【Python】 垃圾回收机制和gc模块
垃圾回收机制和gc模块 Py的一个大好处,就是灵活的变量声明和动态变量类型.虽然这使得学习py起来非常方便快捷,但是同时也带来了py在性能上的一些不足.其中相关内存比较主要的一点就是py不会对已经销毁 ...
- Algorithm --> 动态规划
动态规划 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 什么是动态规划? 动态规划算法通常基于一个递推公式及一个或多个初始状态.当 ...
- Divisor counting [线性筛积性函数]
Divisor counting 题目大意:定义f(n)表示整数n的约数个数.给出正整数n,求f(1)+f(2)+...+f(n)的值. 注释:1<=n<=1000,000 想法:我们再次 ...
- lua对多个精灵执行一系列动作,延时失效
function MainPlayerCards:sendCards() local winSize = cc.Director:getInstance():getWinSize() local nS ...
- openjudge(四)
关于switch的应用: #include <iostream>#include<iomanip>using namespace std;int main(){int a,b; ...
- node初始
### 一.什么是node.js > Node是一个基于 Chrome V8 引擎的 JavaScript 运行环境 > > Node使用了一个事件驱动.非阻塞式 I/O 的模型,使 ...
- alpha冲刺第十天
一.合照 二.项目燃尽图 三.项目进展 之前卡住的注册无法插入数据的问题解决 可以呈现多条数据内容了,首页文章内容呈现,问答界面问题内容呈现 四.明日规划 很多没有完善的,后面还是要继续整改 五.问题 ...