POJ_1604_Just the Facts(阶乘末尾非0位)
来源:互联网 发布:自助域名绑定如何实现 编辑:程序博客网 时间:2024/06/05 06:45
题型:数论
题意:求n!的末尾非0位。
分析:
直接求是不可能了,因为数太大表示不了,但是求末尾非0位,并不需要求出具体的数值,而且末尾的0也是不必要的,所以循环累乘的过程中每次都将末尾的0去掉,并且模上一个数使其保持在一个相对合适的长度,我取的是10^5,不能再小了,在小就WA了。。。
代码:
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#define MOD 100000using namespace std;int n;int main(){ while(~scanf("%d",&n)){ if(n==0){ puts(" 0 -> 1"); continue; } int mul = 1; for(int i=1;i<=n;i++){ mul *= i; while(mul%10==0){ mul/=10; } mul%=MOD; } printf("%5d -> %d\n",n,mul%10); } return 0;}
0 0
- POJ_1604_Just the Facts(阶乘末尾非0位)
- POJ 1604 Just the Facts 阶乘最后非0位
- 阶乘末尾非0
- nyoj1026阶乘末尾非0
- NYOJ1026 阶乘末尾非0 【模板】
- Just the Facts——阶乘计算
- 阶乘末尾0
- 阶乘末尾的0
- POJ_1401_Factorial(阶乘末尾0)
- TOJ1011 阶乘末尾非零数求和
- POJ 1150 The Last Non-zero Digit 阶乘最后非0位
- 阶乘最右边的非0位
- hdu 1066 阶乘最后非0位
- 求阶乘最后一位非0位
- 阶乘末尾0的个数
- 如何求阶乘末尾0
- 阶乘末尾 0 的个数
- 阶乘末尾0的个数
- Linphone Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
- 萧炎
- Android布局FrameLayout的使用
- CI 框架 404 跳转到自己的controller
- hdu4277 DFS+SET
- POJ_1604_Just the Facts(阶乘末尾非0位)
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): 解决方法
- JavaScript CSS Style属性对照表
- SVM (support vector machine) 小小结
- java程序员
- 学籍管理系统数据字典参考
- 调用线程必须为 STA,因为许多 UI 组件都需要(转载)
- davinci平台Uboot移植
- const的作用