hdu 1060 Leftmost Digit

Leftmost Digit

 

       题意很简单,求n^n最左边的数字,因为n=m*10^x 所以lg(n)=lg(m)+x;

       计算的时候注意最大会超出int,要用long

       最近要练练java了

import java.util.Scanner;
public class Main {
	public static void main(String args[])
	{
		long n,T;
		double ans;
		Scanner cin=new Scanner(System.in);
		T=cin.nextLong();
		while(T!=0)
		{
			n=cin.nextLong();
			ans=n*Math.log10(n);
			ans-=(long)ans;
			ans=Math.pow(10, ans);
			System.out.println((int)ans);
			T--;
		}
	}
}

 

时间: 2024-07-28 14:00:28

hdu 1060 Leftmost Digit的相关文章

HDU 1060

Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8550 Accepted Submission(s): 3296 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.     Inp

hdu 1061 Rightmost Digit

      和上一题一样的,只是最右边的数.找规律,20个一循环   import java.util.Scanner; public class Main { final static int a[]={0,1,4,7,6,5,6,3,6,9,0,1,6,3,6,5,6,7,4,9}; static Scanner cin=new Scanner(System.in); static int n,T; public static void main(String[] args) { T=cin

hdu 1066 Last non-zero Digit in N!

        这个方法是参考http://blog.csdn.net/fengyu0556/article/details/5615129 这里的.       证明和推到都在那里面,只是那边最后的代码没有注释和其所说写的又有些出入,所以就贴上我的代码,好理解写   /* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** *

HDU 1546 Idiomatic Phrases Game

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1546 题目: Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 969    Accepted Submission(s): 300 Problem Description Tom is playi

hdu 2795 Billboard

hdu 2795 的传送门–> Problem Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming com

hdu 1527

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1527 hint:威佐夫博弈 基本类似于模板 #include <iostream> #include <cmath> #include <cstdio> using namespace std; const double q = (1 + sqrt(5.0)) / 2.0; // 黄金分割数 int Wythoff(int a, int b) { if (a > b)

hdu 2551 竹青遍野

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2551 hint:就是读懂题就行了 #include <iostream> #include <cstdio> using namespace std; typedef long long LL; LL data[1005]; int main() { data[0]=0; for(int i=1; i<1005; i++) data[i]+=data[i-1]+i*i*i; LL

hdu 2054 A == B?

http://acm.hdu.edu.cn/showproblem.php?pid=2054 此题巨坑,刚开始我以为是简单的水题,就用strcmp过, but错了,后来经过我苦思冥想,结果还有几组数据 0.0 和 0,1.000和1.0 , 但是我不太确定前面的0是不是有作用我还是写了,但是有人过的时候,前面的0没考虑比如: 002和2可能是相等的,也可能是不想等的所以不用判断,只能说明hdu数据不是很强啊,嘿嘿 代码如下: #include <iostream> #include <c

hdu 4430 Yukari&#039;s Birthday

点击打开链接hdu 4430 思路:枚举r+二分k 分析: 1 题目要求的是找到一组最小的r*k,如果r*k相同那么就找r最小的. 2 很明显k>=2,根据n <= 10^12,那么可以知道r的最大值r<50,所以只要枚举枚举r的值,然后二分k的大小找到所有的解,存入一个结构体里面,然后在对结构体排序,那么这样就可以得到最后的ans 3 注意题目说了中心点最多一个蜡烛,所以写二分的时候应该注意判断的条件: 4 还有可能计算得到结果超了long long直接变成负数所以应该对或则个进行判断