最左边一位数

 

Time Limit: 1 Sec  Memory Limit: 128 MB

 

Submit: 1  Solved: 1
原题链接

 

Description

对于给定的正整数N,输出N^N的最左边一位数。

Input

输入包含多组测试数据。输入的第一行是一个整数T,代表测试组数。随后输入T组测试数据,每组测试数据包含一个正整数N ( 1< = N< = 1,000,000,000 ). 

Output

对于每组测试数据,输出N^N次方的最左边一位数。

Sample Input

234

Sample Output

22

HINT

在第一组测试数据中,3 * 3 * 3 = 27,所以最左边一位数是2. 

在第二组测试数据中,4 * 4 * 4 * 4 = 256,所以最左边一位数是2. 

Source

 
算法>---    N^N=N*log10(N);
 
 
 
 
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  double m,N;
  int T;
  cin>>T;
  while(T)
  {
  cin>>N;
   m=N*log10(N);
   //cout<<"m>--"<<m<<endl;
   long long int x=m;
   //cout<<"x>--"<<x<<endl;
   m=m-x;
   //cout<<"m>--"<<m<<endl;
   m=pow(10,m);
   //cout<<"m>--"<<m<<endl;
   x=m;
   cout<<x<<endl;
   T--;
}
    return 0;
}

 

posted @ 2017-03-17 14:56  dearvee  阅读(250)  评论(0)    收藏  举报