zoukankan      html  css  js  c++  java
  • 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的最左位。
     
     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstring>
     4 #include <ctime>
     5 #include <iostream>
     6 #include <algorithm>
     7 #include <set>
     8 #include <vector>
     9 #include <sstream>
    10 #include <queue>
    11 #include <typeinfo>
    12 #include <fstream>
    13 #include <map>
    14 #include <stack>
    15 using namespace std;
    16 #define INF 100000
    17 typedef long long ll;
    18 const int maxn=1010;
    19 
    20 int main()
    21 {
    22     int t;
    23     scanf("%d",&t);
    24     double sum;
    25     while(t--){
    26         ll n;
    27         scanf("%I64d",&n);
    28         sum=n*log10(n);
    29         sum-=(ll)sum;
    30         printf("%I64d
    ",(ll)pow(10.0,sum));
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    其他权益工具
    2股缩为1股
    ubuntu查看网络流量
    修改iphone hosts文件
    Win10 家庭中文版HOST文件更改
    债权投资和其他债权投资的区别
    win10 Administrator没有管理员权限解决方案
    实际发放股票股利
    Could not get lock /var/lib/dpkg/lock
    R语言代写Gibbs抽样的贝叶斯简单线性回归仿真分析
  • 原文地址:https://www.cnblogs.com/RRirring/p/4733960.html
Copyright © 2011-2022 走看看