现在的位置: 首页 > 综合 > 正文

数论 Leftmost Digit

2013年10月18日 ⁄ 综合 ⁄ 共 1543字 ⁄ 字号 评论关闭

Leftmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11015    Accepted Submission(s): 4216


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
Hint
In 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.
 


Author
Ignatius.L
要用G++提交否则会ce;
ac代码:
/*
 * Author:  *****
 * Created Time:  2013/8/31 17:49:10
 * File Name: flip.cpp
 * solve: flip.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<iostream>
#include<vector>
#include<queue>
//ios_base::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clr(x) memset(x,0,sizeof(x))
#define clrs( x , y ) memset(x,y,sizeof(x))
#define out(x) printf(#x" %d\n", x)
#define sqr(x) ((x) * (x))
typedef long long LL;

const int INF = 1000000000;
const double eps = 1e-8;
const int maxn = 30000;

int main() 
{
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        double tmp = n*log10(n);   
        double a = pow(10,tmp - floor(tmp));
        printf("%d\n",(int)a);
    }
    return 0;
}

抱歉!评论已关闭.