zoukankan      html  css  js  c++  java
  • hdu1060

    之前做过的一道题,现在还是拿出来谢谢自己的心得,不是为了叠加博客的内容,而是为了这样每做一道题会一种方法,坚持下去(多吃饭,多运动,多敲代码,多写博客,多陪女朋友,)为了自己的健康,自己开心快乐

    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.
    代码
    #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
     int n,t;
     double a1,a2;
     cin>>t;
     while(t--){
      cin>>n;
      a1=n*(log10(n*1.0));
      //cout<<a1<<endl;
      a2=a1-(__int64)a1;
      //cout<<a2<<endl;
      cout<<(int)pow(10.0,a2)<<endl;
     }
     return 0;
    }
    m=n^n,两边分别对10取对数得 log10(m)=n*log10(n),
    得m=10^(n*log10(n)),由于10的任何整数次幂首位一定为1,
    所以m的首位只和n*log10(n)的小数部分有关
  • 相关阅读:
    Maven下载Jar包(bat脚本)
    在CentOS7环境下安装Mysql
    在CentOS7下安装JDK1.8
    教你如何进行暗网之旅
    在CentOS7下搭建Hadoop2.9.0集群
    查询IP地址的免费API
    HTTP请求代理类(GET 、 POST 、PUT 、DELETE)
    JAVA 实现 GET、POST、PUT、DELETE HTTP请求
    002---rest_framework认证组件
    001---CBV和restful规范
  • 原文地址:https://www.cnblogs.com/ACWQYYY/p/4486146.html
Copyright © 2011-2022 走看看