【杭电-oj】 -1060-Leftmost Digit(输出n的n次方最左边数)
2016-04-17 15:21
459 查看
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
Sample Output
n^n=a*10^m;
两边对10去对数,得n*lg(n)=m+lg(a);
此处接下来用一个数学的pow,例如pow(n,m)表示n^m;
因为1<a<10,所以0<lg(a)<1.
接下来还有一个数学知识,即x^log(x)(n)=n;
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.
n^n=a*10^m;
两边对10去对数,得n*lg(n)=m+lg(a);
此处接下来用一个数学的pow,例如pow(n,m)表示n^m;
因为1<a<10,所以0<lg(a)<1.
接下来还有一个数学知识,即x^log(x)(n)=n;
#include<stdio.h> #include<math.h> int main() { int t,ans; double n; scanf("%d",&t); while(t--) { scanf("%lf",&n); double x,a; x=n*log10(n); a=pow(10,x-(__int64)x); //x-(__int64)x,表示n*lgn的小数部分,即lg(a) ans=int(a); printf("%d\n",ans); } return 0; }
相关文章推荐
- 项目1-数组作数据成员(2)
- 同步容器、并发容器、阻塞队列、双端队列
- javascript VS java
- 数组中的趣味题(二)
- RVO(Return Value Optimization)和NRVO(Named Return Value Optimization)
- GIT 如何合并另一个远程Git仓库的文件到本地仓库里某个指定子文件夹并不丢失远程提交记录
- 网页实现鼠标经过文字后更改颜色
- Window XP驱动开发(十七) 芯片固件程序设计 (代码实现,针对USB2.0 芯片CY7C68013A)
- leetcode 67. Add Binary (高精度加法)
- iOS Coding Standards
- java中的异常
- 数组中的趣味题(一)
- 第八周项目1 数组做类的数据成员(2)
- c编程:输入一个数字n,则n代表n行,每行输入2个数字a,b计算每行的a+b问题。
- 【原创】区块链技术主流开源项目 - Major Open Source Projects of Blockchain Technologies
- 【杭电oj】1052 - Tian Ji -- The Horse Racing(田忌赛马,贪心 & 双端队列)
- 在ubuntu中安装mysql数据库(基于网络的安装)
- (2.2.7)构建工具Maven的选择
- View 的事件体系————读书笔记
- Objective C类方法load和initialize问题集合