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\n",a);

    }

    return 0;

}

Leftmost Digit的更多相关文章

  1. HDU 1060 Left-most Digit

    传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. hdu acmsteps 2.1.8 Leftmost Digit

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字

    1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...

  4. HDU 1060  Leftmost Digit

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  5. Leftmost Digit(数学)

    Description Given a positive integer N, you should output the leftmost digit of N^N.   Input The inp ...

  6. HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. HDU 1060 Leftmost Digit (数论,快速幂)

    Given a positive integer N, you should output the leftmost digit of N^N.  InputThe input contains se ...

  8. Leftmost Digit(hdu1060)(数学题)

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. [js高手之路] html5 canvas系列教程 - 线条样式(lineWidth,lineCap,lineJoin,setLineDash)

    上文,写完弧度与贝塞尔曲线[js高手之路] html5 canvas系列教程 - arcTo(弧度与二次,三次贝塞尔曲线以及在线工具),本文主要是关于线条的样式设置 lineWidth: 设置线条的宽 ...

  2. DOM中document对象的常用属性方法

    每个载入浏览器的 HTML 文档都会成为 Document 对象. Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问. 属性 1  document.anchors  返 ...

  3. vue学习之vue基本功能初探

    vue学习之vue基本功能初探: 采用简洁的模板语法将声明式的将数据渲染进 DOM: <div id="app"> {{ message }} </div> ...

  4. apollo实现c#与android消息推送(四)

    4  Android代码只是为了实现功能,比较简单,就只是贴出来 package com.myapps.mqtttest; import java.util.concurrent.Executors; ...

  5. asp.net core封装layui组件示例分享

    用什么封装?自然是TagHelper啊,是啥?自己瞅文档去 在学习使用TagHelper的时候,最希望的就是能有个Demo能够让自己作为参考 怎么去封装一个组件? 不同的情况怎么去实现? 有没有更好更 ...

  6. 21.Linux-写USB键盘驱动(详解)

    本节目的: 根据上节写的USB鼠标驱动,来依葫芦画瓢写出键盘驱动 1.首先我们通过上节的代码中修改,来打印下键盘驱动的数据到底是怎样的 先来回忆下,我们之前写的鼠标驱动的id_table是这样: 所以 ...

  7. Ubuntu Docker 版本的更新与安装

    突然发现自己的docker 版本特别的低,目前是1.9.1 属于古董级别的了,想更新一下最新版本,这样最新的一下命令就可以被支持.研究了半天都没有更新成功,更新后的版本始终都是1.9.1 :蒙圈了,找 ...

  8. angualrJs清除定时器

    angualrJs清除定时器爬坑之路: 今天发现一个奇怪问题,放在自定义指令里边的定时器竟然在页面跳转之后,在另一个页面这个循环定时器还在执行,这肯定是不行的,会影响系统的性能. 我在angular里 ...

  9. webpack2使用ch3-自动化生成.html和内部引入的js自动更改

    1 安装webpack插件 $ cnpm install html-webpack-plugin --save-dev 安装成功后 2 由于之前 dist/目录下,编译后的.html和.js会混在一起 ...

  10. HDU1201 水题

    做多了年月日,现在基本就能水过了 18岁生日 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...