HDU 2940 Hex Factorial(高精度,打表)
2014-10-08 17:39
274 查看
题目:Hex Factorial
题意:将N!转成十六进制,除去前导0之后,问剩下的数字里面有多少个0。
由于N<=100,所以可以直接写个高精度预处理它,打表秒杀!
要注意数组还是要开大些,十六进制的100!长度也可达到130+。
另外一个注意点是0!= 1,不要漏了。
题意:将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 ); } return 0; }
相关文章推荐
- 高精度 hdu 2940 Hex Factorial
- HDU 2940 Hex Factorial 高精度乘法
- HDU 2940 Hex Factorial(二进制乘法)
- Hex Factorial 高精度
- HDU 2940 Hex Factorial (简单高精度)
- hdu 5351 MZL's Border 打表+高精度
- hdu 5351 MZL's Border(打表+高精度)
- HDU - 2089 不要62 (打表)
- hdu 1056 HangOver (打表水题)
- hdu 1043 八数码--打表
- hdu 2199 Can you solve this equation?(高精度二分)
- hdu 2161 Primes(数学:素数打表+水题)
- HDU 5648 DZY Loves Math 暴力打表
- HDU 4548.美素数【打表】【预处理】【8月11】
- hdu 2510 符号三角形【DFS+打表】
- hdu 5429 Geometric Progression(java 高精度+java输入外挂)
- HDU 1331 将递归改成迭代打表
- Hdu 1063 & Poj 1001 Exponentiation (java 高精度实数 去除首尾0)
- hdu 1042 N! 高精度运算
- HDU 5795 A Simple Nim 打表求SG函数的规律