HDU 2940 Hex Factorial 高精度乘法
来源:互联网 发布:网络攻击与防范 编辑:程序博客网 时间:2024/06/15 05:28
Hex Factorial
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
The expression N!, reads as the factorial of N, denoting the product of the first N positive integers. If the factorial of N is written in hexadecimal without leading zeros, can you tell us how many zeros are there in it? Take 15! as an example, you should answer “3” because (15)10! = (13077775800)16, and there are 3 zeros in it.
Input
The input contains several cases. Each case has one line containing a non-negative decimal integer N (N ≤ 100). You need to count the zeros in N! in hexadecimal. A negative number terminates the input.
Output
For each non-negative integer N, output one line containing exactly one integer, indicating the number of
zeros in N!.
Sample Input
1
15
-1
Sample Output
0
3
题意:给你一个10进制数n 计算n的阶乘转化为16进制后中有多少个0
思路:先吧n转化为16进制 然后按照16进制的进位进行高精度乘法
ACcode:
#include<bits/stdc++.h>using namespace std;#define mmax 10010#define new 16struct Bignum{ int Sz; int num[mmax]; Bignum(int sz,int *a) { Sz=sz; for(int i=0;i<Sz;i++) num[i]=a[i]; } Bignum(int x) { Sz=0; while(x) { num[Sz++]=x%new; x/=new; } } Bignum operator * (const Bignum &a) { int tmp[mmax]; memset(tmp,0,sizeof tmp); for(int i=0;i<Sz;i++) for(int j=0;j<a.Sz;j++) { tmp[i+j]+=num[i]*a.num[j]; } for(int i=0;i<Sz+a.Sz;i++) { tmp[i+1]+=tmp[i]/new; tmp[i]%=new; } for(int i=Sz+a.Sz-1;i>=0;i--) { if(tmp[i]) return Bignum(i+1,tmp); } return Bignum(1,tmp); }};int num[110];int main(){ Bignum ans(1); for(int i=1;i<=100;i++) { ans=ans*Bignum(i); int cnt=0; for(int i=0;i<ans.Sz;i++) { if(ans.num[i]==0) cnt++; } num[i]=cnt; } int n; while(scanf("%d",&n)!=EOF) { if( n < 0) break; printf("%d\n",num[n]); } return 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-1042 高精度乘法
- HDU-1063 高精度实数乘法
- hdu 1042 N! 高精度乘法
- A - Hex Factorial
- A - Hex Factorial
- hdu 1042 N!(高精度乘法 + 缩进)
- hdu 1063 Exponentiation (高精度小数乘法)
- Hdu 5241 Friends【规律+高精度乘法】
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 微信支付返回 -1 无法吊起支付页面 微信分享闪退
- 初学设计模式
- Android开发人员不得不收集的代码(常用的工具类)
- 类的大小
- 导出PDF乱码
- HDU 2940 Hex Factorial 高精度乘法
- 初始者 学习java准备工作
- oracle 创建新表,并复制旧表数据
- pxe 安装centos7.2 制作过程(hp x86 server)
- 第十四周 OJ总结<2>--输入一个数插入有序数组中
- 深入研究Java类加载机制
- thinkphp 通过“命令模式” 定义计划任务
- iOS-SVN无法上传静态库(.a)解决方案
- iOS:Swift自定义print