HDU-1060(简单数学)

Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

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
 
 
分析:求n^n的最前一位数。有log10(n^n)=n*log10(n)=c,令a为c的整数部分,b为c的小数部分,则n^n=10^c=10^a*10^b,即10^b=10^(c-a),10^b的整数部分只有一位就是n^n的最左位。
 
 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
#define INF 100000
typedef long long ll;
const int maxn=; int main()
{
int t;
scanf("%d",&t);
double sum;
while(t--){
ll n;
scanf("%I64d",&n);
sum=n*log10(n);
sum-=(ll)sum;
printf("%I64d\n",(ll)pow(10.0,sum));
}
return ;
}
上一篇:Spring Security构建Rest服务-1201-Spring Security OAuth开发APP认证框架之实现服务提供商


下一篇:项目 Web 的 NuGet 程序包还原失败: 找不到“1.0.0”版本的程序包“Microsoft.Net.Compilers”。。 0