HDU 1060 Leftmost Digit (数论)
来源:互联网 发布:如何爬取网页的js脚本 编辑:程序博客网 时间:2024/06/06 01:20
Leftmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13680 Accepted Submission(s): 5239
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).
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
234
Sample Output
22HintIn 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的最左面的那位数是多少。
解析:高大上的数论,确实对数学的智商不怎么够用。下为借鉴网上大神的思路:
一个数是由每一位的基数乘以相对应的权值,例如 123456 , 基数"1"的权值为 10^5, 基数 "2" 的权值为 10^4......所以该题要求的就是最高位的基数。
对 x^x 取对数,得 x* ln( x )/ ln( 10 ), 现假设这个值为 X.abcdeefg 那么 10^X 就是 最高位对应的权值,10^ 0.abcdefg 就是最高位的基数。注意这里得到的并不是一个整数,为什么呢? 因为这里是强行将后面位的值也转化到最高位上来了,这有点像大数中,如果不满进制却强行进位,显然那样会进给高位一个小数而不是一个天经地义的整数。得到 10^ 0.abcdefg 后,再用 double floor ( double ) 函数取下整就得到最高位的数值大小了
AC代码:
#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){// freopen("in.txt", "r", stdin); int t, n; scanf("%d", &t); while(t--){ scanf("%d", &n); double foo = n * log10(double(n)); //需强转 double ans = foo - floor(foo); printf("%d\n", (int)pow(10.0, ans)); } return 0;}
0 0
- HDU 1060 Leftmost Digit (数论)
- HDU 1060 Leftmost Digit(数论)
- HDU 1060 Leftmost Digit(数论)
- Leftmost Digit(数论)
- Leftmost Digit(数论)
- Leftmost Digit (HDU 1060)
- Leftmost Digit(HDU 1060)
- HDU 1060 Leftmost Digit & BIT1046 Leftmost Digit
- hdoj 1060 Leftmost Digit 【数论】
- Leftmost Digit(对数,数论)
- HDU1060: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
- 杨辉三角
- “cvc-complex-type.2.4.a: Invalid content was found starting with element 'book'”错误的解决办法
- 一些常用可以做测试接口
- java中接口的定义与实现 Java中几种访问权限总结
- 使用U盘模拟软盘
- HDU 1060 Leftmost Digit (数论)
- pat1067 考察了逆向思维
- 多态 ,
- 笔记3_看张鹏老师html+css视频所得
- POJ2001 Shortest Prefixes(字典树)
- Sicily 1093 Air Express
- UVA - 10594 Data Flow (最小费用最大流)
- acm
- NSString的一些用法