A - Hex Factorial
来源:互联网 发布:淘宝店铺货源 编辑:程序博客网 时间:2024/06/06 03:37
A - Hex Factorial
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
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!.
zeros in N!.
Sample Input
115-1
Sample Output
03
题意:题目的意思很简单,就是告诉了我们一个数n,然后让我们求n!的十六进制形式中有多少个0,输入以一个负数结束。
因为N的极限为100,所以要使用高精度,直接暴力跑一遍对于每一个输入找到一个答案然后O(1)询问即可,在转换为16进制的时候一位一位的转换即可。
#include"iostream"#include"cstring"#include"cstdio"using namespace std;int ans[105];int num[2005];void getans(){ memset(ans,0,sizeof(ans)); memset(num,0,sizeof(num)); num[0] = 1; for(int i = 2;i <= 100;i++) { //cout << "***" << endl; int jinwei = 0; for(int j = 0;j < 2005;j++) { int greatnum = num[j]*i + jinwei; num[j] = greatnum % 16; jinwei = greatnum / 16; } int pos; for(pos = 2004;pos >= 0;pos--) if(num[pos]) break; for(int zz = 0;zz < pos;zz ++) if(!num[zz]) ans[i]++; }}int main(void){ int n; getans(); while(~scanf("%d",&n)) { if(n < 0) break; printf("%d\n",ans[n]); } return 0;}
0 0
- A - Hex Factorial
- A - Hex Factorial
- HDU 2940 Hex Factorial
- 高精度 hdu 2940 Hex Factorial
- HDU 2940 Hex Factorial(二进制乘法)
- HDU 2940 Hex Factorial (简单高精度)
- HDU 2940 Hex Factorial 高精度乘法
- Factorial of a number
- lightOj1006 Hex-a-bonacci
- HDU 2940 Hex Factorial(高精度,打表)
- LightOj 1006 - Hex-a-bonacci
- LightOJ 1006 Hex-a-bonacci
- LightOJ 1006 :Hex-a-bonacci
- LightOJ 1006 - Hex-a-bonacci
- LightOJ-1006-Hex-a-bonacci
- Factorial!
- Factorial
- Factorial
- 数据结构之线性表学习总结
- 解决跨站脚本注入,跨站伪造用户请求,sql注入等http安全漏洞
- LeetCodeOJ_200_Number of Islands
- [笔记]python template 模板
- 【Unity】相机跟随主角移动,并带有延迟效果
- A - Hex Factorial
- CentOS配置防火墙
- Mac os YOsemite 10.10安装Metasploit
- Eclipse failed to create jvm
- vmbox-android
- Qt学习记录4——mainwindow的布局使用
- hdu 1671 字典树
- Extension 类扩展
- Unity 3D + Vuforia制作AR人物互动