ZOJ 2277 The Gate to Freedom(n^n)
来源:互联网 发布:安捷伦数据采集仪 编辑:程序博客网 时间:2024/06/17 02:22
Background
It is dark at night.
It is silence at night.
It is she in the dark.
It is she in the silence.
Then a light appeared. A huge gate came into our sights, called
The Gate to Freedom
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?"
题意:求n^n结果最左边的数
思路方法:之前有些过N^N求最后一位的数字,那是各种姿势都可做。可是这道题似乎就没那么简单的说。但是。。。
设: n^n = k * 10^b (4^4 = 1.6 * 10^1)
两边对10取对数:n*log10(n) = log10(k * 10^b) = log10(k) + b
可得:log10(k) = n*log10(n) - b
然后因为0<k<10,所以0<log10(k)<1,然后可以发现: b = floor(n*log10(n)),也就是 n*log10(n) 的整数部分(floor()用于向下取整,返回值为double)
计算可得:x = n*(log10(n))-floor(n*(log10(n)))
所以:k = floor(pow(10,x)),取第一位就是答案
#include<iostream>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<cstdlib>#include<cstdio>#include<set>#include<map>typedef long long LL;using namespace std;int main(){ double n; while(scanf("%lf",&n)!=EOF){ double x = n*(log10(n))-floor(n*(log10(n))); double k = floor(pow(10,x)); printf("%.0f\n",k); } return 0;}
- ZOJ 2277 The Gate to Freedom(n^n)
- zoj 2277 The Gate to Freedom
- ZOJ 2277 The Gate to Freedom
- zoj 2277 The Gate to Freedom
- ZOJ.2277 The Gate to Freedom【数论-海伦】 2015/09/16
- zoj2277 The Gate to Freedom
- ZOJ 2281 Way to Freedom
- ZOJ 2281 Way to Freedom
- ZOJ 3175 Number of Containers(n/1+n/2+...+n/(n-1)+n/n求法)
- zoj 3175 Number of Containers (nbut1375) 计算n /1+n/2+n/3+n/4....+n/n
- poj3239 Solution to the n Queens Puzzle (n皇后问题)
- ZOJ 2281 Way to Freedom(最短路变形-寻找最大流)+ POJ 1797
- PKU3239 Solution to the n Queens Puzzle
- POJ3239 Solution to the n Queens Puzzle
- zoj 2281 Way to Freedom(最短路加强版)
- BZOJ_P3101 N皇后/POJ_P3239 Solution to the n Queens Puzzle(N皇后构造)
- the algorithms to solve the question X^N
- Find the missing integer from 0 to n
- 51nod 1419:最小公倍数挑战
- iOS 中播放gif图片
- 在定点二进制运算器中,减法运算一般通过什么来实现
- UUID
- little kernel代码片段
- ZOJ 2277 The Gate to Freedom(n^n)
- linux shell进行文件去重
- [笔记]利用归并排序计算逆序数的个数
- POJ 1321 棋盘问题
- 事务处理
- php接口测试 curl实现GET/POST
- 鸟哥私房菜学习笔记六 Bash
- 逆序对 (归并排序)
- html5开发之viewport使用