HDU 6433(2的n次方 **)
题意是就是求出 2 的 n 次方。
直接求肯定不行,直接将每一位存在一个数组的各个位置即可,这里先解出 2 的 n 次方的位数,再直接模拟每一位乘以 2 即可得到答案。
求解 2 的 n 次方的位数的方法:len = n * lg(2) (lg(2):以 10 为底 2 的对数)
证明:在判断一个数有多少位时,常将这个数多次除以 10,够除多少次,就是几位数。设 2 的 n 次方有 k 位数,则 2 ^ n < 10 ^ k,两边同时以 10 为底取对数,则 n * lg(2) < k ,那么 2 的 k 次方的位数就等于对 n * lg(2) 向上取整。
(其实个人对于这个证明不太满意)
在 咸鱼98 同学的指点下,对于求解 2 的 n 次方的位数的方法有了更好的证明:
ans = 2^n;
len = log(10, ans); //以 10 为底 ans 的对数向上取整就是ans的长度
len = log(10, ans) = log(10, 2) * log(2, ans) ; //换底公式
log(2, ans) = log(2, 2^n) = n;
len = log(10, 2) * n;
代码如下:
#include <bits/stdc++.h>
using namespace std;
int t,n,ans[];
int main()
{
scanf("%d",&t);
while(t--)
{
memset(ans,,sizeof(ans));
scanf("%d",&n);
ans[] = ;
int len = n*0.301029;//log(2) = 0.301029995663981195...
while(n--)
{
for(int i = len; i >= ; i--)
{
ans[i+] += ans[i]/; // ans[i+1] += ans[i]*2/10
ans[i] = (ans[i]*)%;
}
}
for(int i = len; i >= ; i--)
printf("%d",ans[i]);
printf("\n");
}
return ;
}
HDU 6433(2的n次方 **)的更多相关文章
- HDU——1061Rightmost Digit(高次方,找规律)
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 6433: H. Pow (简答题,输出大数)
There are n numbers 3^0, 3^1, . . . , 3^n-1. Each time you can choose a subset of them (may be empty ...
- HDU 1061 N^N (n的n次方的最后一位)
题目意思: http://acm.hdu.edu.cn/showproblem.php?pid=1061 求N^N的最后一位数. 题目分析: 此题有非常多种方法,主要是中循环节,看自己怎么找了.我的方 ...
- hdu 4059 数论+高次方求和+容斥原理
http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...
- HDU 5407——CRB and Candies——————【逆元+是素数次方的数+公式】
CRB and Candies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...
- HDU 5053 the Sum of Cube
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5053 解题报告:用来陶冶情操的题,求a到b的三次方的和. #include<stdio.h> ...
- HDU 4578 Transformation (线段树区间多种更新)
http://acm.hdu.edu.cn/showproblem.php?pid=4578 题目大意:对于一个给定序列,序列内所有数的初始值为0,有4种操作.1:区间(x, y)内的所有数字全部加上 ...
- HDU 4915 Parenthese sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 解题报告:从前往后遍历一次,每次判断')'的数目是不是满足 n < (i +1)/ 2,从 ...
随机推荐
- MT【306】圆与椭圆公切线段
已知椭圆方程$\dfrac{x^2}{4}+\dfrac{y^2}{3}=1$,圆方程$x^2+y^2=r^2,(3<r^2<4)$,若直线$l$与椭圆和圆分别切于点$P,Q$求$|PQ| ...
- 「HAOI2018」染色 解题报告
「HAOI2018」染色 是个套路题.. 考虑容斥 则恰好为\(k\)个颜色恰好为\(c\)次的贡献为 \[ \binom{m}{k}\sum_{i\ge k}(-1)^{i-k}\binom{m-k ...
- 关于Autosar中的NM模块的理解
本篇文章主要介绍AutoSar中关于NM模块的理解. 阅读本篇文章希望达到的目的: 1. NM(网络管理)是用来做什么的: 2. AutoSar中网络管理的原理: 3.项目实例介绍 1. NM(网络管 ...
- hdu 2328 Corporate Identity(kmp)
Problem Description Beside other services, ACM helps companies to clearly state their “corporate ide ...
- nginx+腾讯云免费ssl证书+阿里云ECS实现Https配置
1. 申请SSL证书: 首先我们需要到腾讯云那边申请一个ssl证书,对于个人博客类型的,建议采用免费版本,土豪除外 申请地址:https://console.cloud.tencent.com/ssl ...
- Jupyter Notebook 编辑器美化
汇总系列:https://www.cnblogs.com/dunitian/p/4822808.html#ai 2018-10-10新增Linux样式路径: Logo: ~/anaconda3/lib ...
- 上pixiv解决法(保存)
C:\Windows\System32\drivers\etc\hosts 127.0.0.1 localhost 127.0.0.1 advstat.xunlei.com 127.0.0.1 cl. ...
- poj1442 Black Box
The Black Case 好啊! 首先,读题很艰难... 读完题,发现是求第k小的数,那么我们用splay水过对顶堆水过即可. #include <cstdio> #include & ...
- A1131. Subway Map (30)
In the big cities, the subway systems always look so complex to the visitors. To give you some sense ...
- A1046. Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...