【杭电oj】1060 - Leftmost Digit(数学好题)
2016-01-13 17:18
387 查看
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15463 Accepted Submission(s): 6000
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
巧用lg转化,下面是我用mathtype打出的解题过程:
另外注意,对x取整时应该用__int64,用int会越界,用long int时oj会判PE。
代码如下:
#include <stdio.h> #include <math.h> int main() { int u; int ans; double num,a; double x; scanf("%d",&u); while(u--) { scanf("%lf",&num); x=num*log10(num); a=pow(10.0,x-(__int64)x); ans=int(a); printf("%d\n",ans); } return 0; }
相关文章推荐
- 老李分享:集群
- View工作原理(三)视图大小计算过程(measure过程)
- linux学习笔记----7
- 详解JavaScript中localStorage使用要点
- 自定义 NSOperation
- 万变的生活中可以复制的持续发展之路:反省
- Android HandlerThread使用方法
- Zoho Reports让数字图形化
- WEB开发中的页面跳转方法总结
- 老李分享: 并行计算基础&编程模型与工具 2
- LightOJ 1214 - Large Division (大数求余)
- 上传插件webuploader.js的使用示例
- View工作原理(二)导致View重建原因
- iOS开发笔记--静态库的制作与使用
- 编程概念
- 图标和文字居中
- 老李分享: 并行计算基础&编程模型与工具 1
- linux 安装python2.7.11
- Git 版本控制命令符
- eclipse中启动Tomcat发布工程,工程的发布目录