Leftmost Digit(数学)
Description
Input
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
Sample Input
3
4
Sample Output
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结果的第一位。
解题思路:我们可以将其看成幂指函数,那么我们对其处理也就顺其自然了,n^n = 10 ^ (log10(n^n)) = 10 ^ (n * log10(n)),
然后我们可以观察到: n^n = 10 ^ (N + s) 其中,N 是一个整数 s 是一个小数。由于10的任何整数次幂首位一定为1,所以首位只和s(小数部分)有关。
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long int
using namespace std;
int main()
{
int t,n;
double m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
m=n*log10(n);
m=m-(ll)(m);
m=pow(10.0,m);
printf("%d\n",(int)(m));
}
return ;
}
Leftmost Digit(数学)的更多相关文章
- HDU 1060 Leftmost Digit (数学/大数)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...
- HDU 1060 Left-most Digit
传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- hdu acmsteps 2.1.8 Leftmost Digit
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Leftmost Digit
Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input ...
- HDU 1060 Leftmost Digit
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
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(hdu1060)(数学题)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- Model验证简单易懂
public bool UserSex { get; set; } //定义名字 [Display(Name = "年龄")] [Range(0, 150, ErrorMessag ...
- Excel工作表保护的密码破解与清除...假装自己破解密码系列?
有一次我女朋友让我帮忙解一个excel表格的保护密码,然后~用了宏 网上下载来的Excel经常会有工作表保护,也就是无法修改,妄图做任何修改的时候你就会看见这句话: 您试图更改的单元格或图表位于受保护 ...
- ubuntu18.10手动安装mysql5.5
一.问题描述 本人使用的电脑安装的是ubuntu18.10系统,使用aptitude install mysql-server命令安装mysql时,总是无法正常安装,无法正常配置mysql-serve ...
- IIS配置导入导出
使用管理员身份运行cmd 应用程序池: # 导出所有应用程序池 %windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\a ...
- Vue基础学习(纯属个人学习的笔记,慢慢新增)
1.在html文件中,声明了template对象,那么在 data对象中的v-html和v-text的绑定数据是不起作用的 2.v-的几个常用绑定 v-html和v-text:引用的conten ...
- Chino 操作系统开发日志 (1) - 为 IoT 而生
引言 很多人都听说过 IoT (物联网)这个词,越来越多的人在装修时开始选择智能家居,很多人也购买智能音箱做智能家居控制,想必未来一定是 AI + 物联网的时代. 一种技术要发展并走向成熟必须要降低门 ...
- [转] JetBrains Products License Server,适用RubyMine、Goland等
原文:http://jetbrains.license.laucyun.com/ Working Server http://jetbrains.license.laucyun.com (Lower ...
- HTML5新增元素,标签总结
总是遇到h5新标签的笔试题目,就查阅了资料来总结一下: 1.form相关: (1)form属性:在HTML5中表单元素可放在表单之外,通过给该元素添加form属性来指向目标表单(form属性值设为目标 ...
- 20155322 2016-2017-2 《Java程序设计》第三周学习总结
20155322 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 本周学习的内容主要为教材的第四第五章,下面是总结: 第四章 主要讨论了五个问题:类与对象.基 ...
- 洛谷 P3369 【模板】普通平衡树(Treap/SBT)
题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数 删除x数(若有多个相同的数,因只删除一个) 查询x数的排名(排名定义为比当前数小的数的个数+1.若有多 ...