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)的小数部分有关
  • 相关阅读:
    类的静态成员
    透彻分析C/C++中memset函数
    排序中的qsort和sort
    NOIP2020 T4微信步数
    NOIP2020 T3移球游戏
    GMOJ 6898. 【2020.11.27提高组模拟】第二题
    虚树学习笔记
    GMOJ 6860. 【2020.11.14提高组模拟】鬼渊传说(village)
    CSP-S 2020 T3函数调用
    CSP-S 2020 T4贪吃蛇
  • 原文地址:https://www.cnblogs.com/ACWQYYY/p/4486146.html
Copyright © 2011-2022 走看看