hdu 1060 Leftmost Digit
来源:互联网 发布:网络上没有找到打印机 编辑:程序博客网 时间:2024/05/29 04:42
题目:
Leftmost Digit
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 1060
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的第一位
题目思路:
1、因为n*n如果用大数来计算,那必定会超时,而且题目只要求第一位,所以需要其他方法来求解
2、用数学方法就得化简转化
n^n=10^m+a // a的int型就是要求的答案
N*lgn=m+lga
10^(n*lgn-m)=a
而m为n*lgn的整数部分
所以原式=10^fomd(n*lgn);
程序:
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<cmath>#include<algorithm>#include<cctype>#include <fstream>#include <limits>#include <vector>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <cassert>using namespace std;int main(){ int ci; scanf("%d",&ci); while(ci--) { double n; cin>>n; int ans=pow(10,fmod(n*log10(n),1)); cout<<ans<<endl;; }return 0;}
- HDU 1060 Leftmost Digit & BIT1046 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 LeftMost Digit
- HDU 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu - 1060 - Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- HDU-1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- ubuntu 的使用 —— 解压 rar 文件
- 转载一篇搭建svn服务器的文章。出处为http://www.ha97.com/4467.html
- Notepad++中删除连续的任意n行
- PAT L2-007. 家庭房产(并查集)
- Dubbo源码分析1
- hdu 1060 Leftmost Digit
- 最长公共子序列 && 最长公共字串
- Android中Preference的使用以及监听事件分析
- AJAX中GET与POST的区别
- 基于DDD的.NET开发框架 - ABP初探
- Dubbo源码分析2
- 学习iOS、React Native、算法开发的建议
- 搭建mongodb集群之副本集
- iOS数据持久化文件读写之偏好设置