杭电 1060
来源:互联网 发布:台州学院网络教学平台 编辑:程序博客网 时间:2024/06/05 11:05
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12947 Accepted Submission(s): 4953
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).
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
234
Sample Output
22HintIn 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
一看题上的 数值范围 就知道一般的数值类型没法表示 考虑到__int64
又因为n^n数值太大 考虑用指数表示法
则有n^n=a*10^x;
等号两边对10取对数得 n*log10n=lga+x;
则lga=(n*lgn-x)
x可以通过对n*lgn向下取整求得
则有lga=(n*lgn-[n*lgn])
所以有以下代码:
#include<stdio.h>
#include<math.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
__int64 n,s;
double m;
scanf("%I64d",&n);
m=n*log10(n+0.0);
m-=(__int64)m;
s=(__int64)pow(10,m);
printf("%I64d\n",s);
}
return 0;
}
#include<math.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
__int64 n,s;
double m;
scanf("%I64d",&n);
m=n*log10(n+0.0);
m-=(__int64)m;
s=(__int64)pow(10,m);
printf("%I64d\n",s);
}
return 0;
}
0 0
- 杭电1060
- 杭电 1060
- 杭电acm 1060
- 杭电1060 Leftmost Digit
- 【杭电】[1060]Leftmost Digit
- 杭电
- 杭电
- 杭电
- 杭电HDOJ 1060 解题思路
- 杭电OJ 1060 :Leftmost Digit
- 杭电acm hdu-1060Leftmost Digit
- 杭电 HDU 1060 Leftmost Digit
- 杭电 1234 和 杭电 2115
- 杭电2056之Rectangles 杭电
- 杭电ACM1061Rightmost Digit
- 杭电2099 7.11
- 杭电ACM 1003
- 杭电 ACM 2016
- FrameLayout measure过程源码Log全解析之二:修改framework代码,输出Log
- SQlServer 安装出错:未指定 INSTANCESHAREDWOWDIR 命令行值
- LUA面向对象程序设计(六)数据的封装
- 智能家居:智能中心还是消息总线(I)
- HDU4597:Play Game(记忆化)
- 杭电 1060
- 黑马程序员 - 学习笔记2 对象 类 方法 属性
- java笔记-多线程-线程安全
- javaScript 超时与间歇掉用
- 多项式求和(杭电2011)
- Linux成为只读模式解决办法
- js实现简单自定义导航,导航随项目id变化(ECMS下内容页修改)
- 长沙农天农业科技有限公司人口过亿的国家
- zoj 1721 (bellmanford)