HDU 2940 Hex Factorial(高精度,打表)
来源:互联网 发布:翼龙贷java 待遇 编辑:程序博客网 时间:2024/06/05 18:40
题目:Hex Factorial
题意:将N!转成十六进制,除去前导0之后,问剩下的数字里面有多少个0。
由于N<=100,所以可以直接写个高精度预处理它,打表秒杀!
要注意数组还是要开大些,十六进制的100!长度也可达到130+。
另外一个注意点是0!= 1,不要漏了。
#include<cstdio>#include<cstring>struct BigInt{ int x[200]; BigInt(){} BigInt(int n){ memset(x, 0, sizeof(x)); for(int i=0; n; i++,n>>=4){ x[i] = n&15; } } void mul(int n){ for(int i=0; i<200; i++){ x[i] *= n; } for(int i=0; i<199; i++){ x[i+1] += (x[i]>>4);//等价于除以16 x[i]&=15;//等价于模16 } } int count(){ int i; for(i=199; i>0; i--){ if(x[i]) break;//除去前导0 } int cnt = 0; for(i; i>=0; i--){ if(!x[i]) cnt++; } return cnt; }};int ans[110];void init(){ BigInt A = BigInt(1); ans[0] = 0; for(int i=1; i<=100; i++){ A.mul(i); ans[i] = A.count(); }}int main(){ init(); int n; while(~scanf("%d", &n) && n>=0){ printf("%d\n", ans[n]); } return 0;}
0 0
- HDU 2940 Hex Factorial(高精度,打表)
- 高精度 hdu 2940 Hex Factorial
- HDU 2940 Hex Factorial (简单高精度)
- HDU 2940 Hex Factorial 高精度乘法
- HDU 2940 Hex Factorial
- HDU 2940 Hex Factorial(二进制乘法)
- hdu 5351 MZL's Border(打表+高精度)
- hdu 1715 大菲波数(高精度加法+打表 + 斐波那契数)
- hdu 1297 Children’s Queue(高精度加法+情况分析+打表)
- 区间素数 (高精度+打表)
- A - Hex Factorial
- A - Hex Factorial
- HDU 1124 Factorial (數論)
- HDU 1124 Factorial(数论)
- HDU 1124 Factorial(数论)
- 阶乘 hdu 1124 (Factorial)
- Digits of Factorial (求N!的k进制位数)(打表)
- hdu 4715(打表)
- 育儿好书推荐
- 【C#】窗体控件随窗体大小改变(包括字体大小)
- 修改android4.0系统的设置的小标题栏
- Python中使用POST方式上传文件
- iOS开发笔记之十九——一个模态视图切换bug引发的思考
- HDU 2940 Hex Factorial(高精度,打表)
- dup , dup2的剖析
- SDUTOJ 2093 Fermat’s Chirstmas Theorem 素数筛
- flex强制类型转换
- [分享]云主机,虚拟机,VPS该注意哪些优化呢?
- 删除恢复Hadoop集群中的DataNode
- 通过PowerShell获取Windows系统密码Hash
- AutoLayout学习常见问题
- Android 各种Context区别