ACM Steps 2.1.7
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3377 Accepted Submission(s): 1485
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.
Author
Ignatius.L 题意: 求N^N的最左边那位数。 思路: 从网上找到的一个公式:N^N=10^(log10(N^N))=10^(N*log10(N)),此结果可以分为10的整数次幂乘以10的小数次幂,这就转换为求10的小数次幂中 第一个数。(至于10的小数次幂结果大于1小于10。。。。。。。。。。)
代码:
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
int main()
{
int t;
double a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&a);
b=a*log10(a);
long long c=b;
b=b-c;
b=pow(10,b);
int d=b;
printf("%d\n",d);
}
return 0;
}
ACM Steps 2.1.7的更多相关文章
- HDOJ acm steps 3.1.1
(都是递推求值,呵呵,好开心- - ) 今天又是在自习室通宵(文明玩的停不下来了) 游戏玩完想想该水题了,于是打开了HDOJ的ACM STEPS(这是个好东西,就像他的名字,一步步来的) 2.3.x貌 ...
- hdu acm steps Big Event in HDU
上网搜了一下这道题的解法,主要有两个方法,一种是采用母函数的方法,一种是采用0/1背包的方法. 先说一下母函数,即生成函数,做个比喻,母函数就是一个多项式前面的系数的一个整体的集合,而子函数就是这个多 ...
- ACM STEPS——Chapter Two——Section One
数学题小关,做得很悲剧,有几道题要查数学书... 记下几道有价值的题吧 The area(hdoj 1071) http://acm.hdu.edu.cn/showproblem.php?pid=10 ...
- hdu ACM Steps Section 1 花式A+B 输入输出格式
acm与oi很大的一个不同就是在输入格式上.oi往往是单组数据,而acm往往是多组数据,而且题目对数据格式往往各有要求,这8道a+b(吐槽..)涉及到了大量的常用的输入输出格式.https://wen ...
- ACM Steps 2.1.8
小数化分数2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- ACM Steps 2.1.4
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 2015寒假ACM训练计划
1月26号至3月4号 每天给自己一个计划.做有意义的事情,不要浪费时间. 8:00——11:30 acm训练 11:30——13:00 午休 13:00——17:30 acm训练 17:30——18 ...
- hdu 1087 动态规划之最长上升子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...
- hdu 2955 01背包
http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...
随机推荐
- MySQL5.7中新增的JSON类型的使用方法
创建表json_test: CREATE TABLE json_test(id INT(11) AUTO_INCREMENT PRIMARY KEY,person_desc JSON)ENGINE I ...
- HTML5_ScrollInToView方法
scrollIntoView(ture)元素上边框与视窗顶部齐平 scrollIntoView(false)元素下边框与视窗底部齐平 <html> <head> <tit ...
- C#中Invoke的用法()
invoke和begininvoke 区别 一直对invoke和begininvoke的使用和概念比较混乱,这两天看了些资料,对这两个的用法和原理有了些新的认识和理解. 首先说下,invoke和beg ...
- POJ 3349 HASH
题目链接:http://poj.org/problem?id=3349 题意:你可能听说话世界上没有两片相同的雪花,我们定义一个雪花有6个瓣,如果存在有2个雪花相同[雪花是环形的,所以相同可以是旋转过 ...
- SpringMVC中向服务器传递时间参数时出现的问题
1. 问题描述: 今天在SpringMVC应用中上传参数的时候遇到如下问题: The request sent by the client was syntactically incorrect 这说 ...
- sprint3冲刺第一天
1.计划了sprint3要做的内容: 整合前台和后台,然后发布让用户使用,然后给我们反馈再进行改进 2.backlog表格: ID 任务 Est 做了什么 1 实现用户登录与权限判定 4 进行用户分类 ...
- 读书笔记和sprint总结
第八章 需求分析 主要是讲需求的分析,对于一个程序项目来说,我觉得,需求是这个项目的向导,他可以决定程序项目会发展成什么样子.书里面需求这里大致分为两个:软件需求和用户需求. 软件需求:我们不仅仅要 ...
- 解决ADT升级报错
方法一: 将https://dl-ssl.google.com/android/eclipse/ 改成 http://dl-ssl.google.com/android/eclipse/: 方法二: ...
- Ue4 BatteryCollector 教程笔记
H UFUNCTION(BlueprintNativeEvent) void EventName(); virtual void EventName_Implementation(); EventNa ...
- c#如何使用正则表达式ZZ
什么是正则表达式 正则表达式是用来检验和操作字符串的强大工具.简单的理解正则表达式可以认为是一种特殊的验证字符串.正则表达式常见运用是验证用户输入信息格式,比如上面的那组"\w{1 ...