Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14954    Accepted Submission(s): 5775

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
 
Recommend
We have carefully selected several similar problems for you:  1018 1071 1573 1066 1004
 
没有思路,直接百度的
 
m=n^n;
linag两边同时log10
log10(m)=log10(n^n)=n*log10(n);
所以,m=10^(n*log10(n));
m的最左边一位由n*log10(n)的小数部分决定。m=10^((n*log10(n))的整数部分)+10^((n*log10(n))的小数数部分);10的整数次方肯定是1000……,最左边一位由10^((n*log10(n))的整数部分)决定。
 
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; int main()
{
int T;cin>>T;
while(T--)
{
double n;
cin>>n;
double m=n*log10(n);
double p=m-(long long)m;
double q=pow(,p);
cout<<(long long)q<<endl;
} return ;
}
以后遇到大数,可以考虑log,考虑转换成指数形式,
另外大数数学的题,不要用int,用 long long,第一次就是用int,所以wa了一次。

最新文章

  1. Visual Studio 2015 如何将全英界面转成中文
  2. Phylab2.0 文档汇总
  3. Spring整合jdbc
  4. StringBuilder 拼接sql语句比较快
  5. Foundation of 3D computer Graphics--Reading notes
  6. python 抓取javascript 动态数据
  7. 关于Oracle的rac集群和mysql Galera Cluster的想法
  8. CString的GetBuffer用法,GetBuffer本质,GetBuffer常见问题解决方法
  9. mongoDb 给表添加+ 删除字段
  10. css3绘制几何图形
  11. Java Web项目报错总结
  12. SQLI DUMB SERIES-16
  13. skywalking部署
  14. JAVA 最新 环境搭建(JDK 1.8 + Tomcat 9 + eclipse oxygen + mysql 5.7)
  15. shiro默认登录
  16. 云笔记项目-Java反射知识学习
  17. 从零开始学 Web 之 CSS3(八)CSS3三个案例
  18. EntityFramework Core
  19. vim+xdebug调试PHP
  20. [Cpp primer] range for (c++11)

热门文章

  1. adb shell am/pm 常用命令详解与使用
  2. 【03】Chrome提示印象笔记剪藏插件"已停用不支持的扩展程序"怎么办?
  3. chrome 下载插件包及离线安装 附 Advanced Rest Client 下载
  4. python---类接口技术
  5. 2017 ACM/ICPC Asia Regional Qingdao Online
  6. iossharesdk微信登录出错
  7. Educational Codeforces Round 13——D. Iterated Linear Function(矩阵快速幂或普通快速幂水题)
  8. 北京集训TEST16——图片加密(fft+kmp)
  9. 高一python笔记大全(过会考)
  10. Cstring中GetBuffer()方法的主要作用