The Gate to Freedom (数学思维题)
2019-03-10 19:37
288 查看
ZOJ Problem Set - 2277
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2277
Problem
There’re some words on the gate: “This gate will lead you to freedom. First, you have to open it. I have a problem for you to solve, if you answer it correctly, the gate will open!”
“Tell me, young boy, what is the leftmost digit of N^N?”
Input
This problem contains multiple test cases.
Each test case contains an integer N (N<=1,000,000,000).
Output
For each test case, output the leftmost digit of N^N.
Sample Input
3
4
Sample Output
2
2
给你一个N,求N^N第一位数字是几。
这个题用lg10写。
比如5 = 10lg5
首先:这个题可以换成所以 N^N = 10N*lgN
其次:比如108.3 = 108 * 100.3, 108第一位就是1,所以第一位数是几取决于 100.3,算这个 100.3就行了。
代码如下:
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { double n; while(scanf("%lf",&n)!=EOF) { double a = n*(log10(n)); 如果对应上边那个例子,这个a = 5.8; ll b = (n*log10(n)); b = 5; int x = (int)pow(10, a-b); 10^0.8 就是结果了 printf("%d\n",x); } return 0; }
相关文章推荐
- zoj 2277 The Gate to Freedom
- 【ZOJ2277】The Gate to Freedom
- ZOJ 2277 The Gate to Freedom
- ZOJ 2277 The Gate to Freedom(n^n)
- zoj 2277 The Gate to Freedom
- zoj 2277 The Gate to Freedom
- zoj2277 The Gate to Freedom
- (CodeForces 883A) The Meaningless Game 纯正的数学思维题(有点卡cin时间)
- The 2016 ACM-ICPC Asia China-Final Contest H题 数学 + 思维
- [jumping to the gate] 娱乐向setjmp
- Codeforces Gym 100379J Move the (p, q)-knight to the corner! 组合数学DP, Lucas定理
- codeforces The Meaningless Game 数学思维
- 数学/思维 UVA 11300 Spreading the Wealth
- 【Codeforces 869 C The Intriguing Obsession】& 组合数学 & 思维
- zoj 2722 Head-to-Head Match(数学思维)
- zoj 2818 Root of the Problem(数学思维题)
- HDU 2268 How To Use The Car (数学题)
- 【HPU-OJ】Divide the pears(数学,思维)
- Codeforces Round #418 (Div. 2)-B. An express train to reveries-思维
- Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.