Leftmost Digit
来源:互联网 发布:工作室监控软件 编辑:程序博客网 时间:2024/06/05 09:14
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.
此题是数论水题,只需要运用对数运算,将n^n,用科学技术法表示然后在对系数取整即可。
#include<iostream>
#include<cmath>
using namespace std;
int n;
int main(){
int a;
long double f;
double x;
while(cin>>n){
while(n-->0){
cin>>a;
f=a*log10(a*1.0)-(long long)(a*log10(a*1.0));
long double d=10;
x=pow(d,f);
cout<<int(x)<<endl;
}
}
return 0;
}
0 0
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- 20140823 N2
- ADT下载地址整理
- 云笔记使用的感受想法!(对有道云笔记、印象云笔记的比较与评价)
- Linked List Cycle
- C语言之基础数据类型分析
- Leftmost Digit
- Chap2 Insertion Sort
- 查看Eclipse版本号及各个版本区别 .
- 虚拟存储器
- 今天真是郁闷,,
- java并发[一]探索获取合理的并发数
- grep
- Sudoku Solver
- WARNING: Waited 15 secs for write IO to PST disk 4 in group 3 in alert_asm.log