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).
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题目大意:让你求解n的n次方的首位数字,并且输出这个数字。这个题目其实用到了log以及科学计数法。最重要的是数字的范围,尽量采用long long否则wa的话会很不爽。解题步骤:纯粹的数学分析。![]()
#include <cmath> using namespace std; int main() { long long int n; long double x; long double log10a; long double a; cin>>n; while(n--){ cin>>x; log10a=x*log10(x)-(long long int)(x*log10(x)); a=pow(10,log10a); cout<<(int)a<<endl; } }