zoukankan      html  css  js  c++  java
  • Leftmost Digit

    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.
    
    
    题意:给你一个数n让你求n^n最高位的数;
    
    
    解题思路:那天上午在实验室写了这个题,刚开始看到数很大就寻思找规律,结果输出不到20位,数就太大了,回来之后想了好几天,后来又借鉴了大神的思路,知道了。
    
    
    num^num=10^n*a;a的整数部分就是这个数的最左边的那一位; 对两边取对数  num*log10(num)= n+lg(a);n+lg(a)这个数中,n肯定是个整数,lg(a)肯定是个小数;
    
    
    代码:
    
    
    
    #include
    using namespace std;
    int main()
    {
        //freopen("in.txt","r",stdin);
        unsigned long n;
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%ld",&n);
            double x=n*log10(n*1.0);
            //cout<<"(__int64)x="<<(__int64)x<<endl;
            x-=(__int64)x;
            //cout<<"x="<<x<<endl;
            int a=pow(10.0, x);
            printf("%d ",a);
        }
        return 0;
    }
  • 相关阅读:
    计算机世界中解决问题的三种技术手段
    应用程序池的经典模式与集成模式的区别
    sh文件的编译
    flex学习开始了
    com,ActiveX,Ole之间的关系学习总结
    "正在等待localhost。。”问题的解决
    一些感悟
    面向对象软件工程方法学实践【转】
    外连接在sqlserver和access之间的差异
    外连接在sqlserver和access之间的差异
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/5781544.html
Copyright © 2011-2022 走看看