hdu 1060 leftmost digit
2015-10-30 00:09
417 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060
思路:nlogn的第一位小数位取出来,再求10的密就是我们要的结果了,不解释,就是这么叼。
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
#include <iostream>
#include <cmath>
using namespace std;
int main(){
long double x;
int n;
cin>>n;
while(n--){
cin>>x;
long double xx = log10((long double)x);
xx *= x;
long double bit = xx - (long long)xx;
x = pow(10 , bit);
cout<<(int)x<<endl;
}
}
思路:nlogn的第一位小数位取出来,再求10的密就是我们要的结果了,不解释,就是这么叼。
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
#include <iostream>
#include <cmath>
using namespace std;
int main(){
long double x;
int n;
cin>>n;
while(n--){
cin>>x;
long double xx = log10((long double)x);
xx *= x;
long double bit = xx - (long long)xx;
x = pow(10 , bit);
cout<<(int)x<<endl;
}
}
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 【OJ日志】超级约瑟夫
- 【OJ日志】爬楼梯
- 【OJ日志】删除升序数组的重复数字
- 几个比较大的在线提交系统(Online Judge)
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- ACM题库以及培养策略