hdu 1066
来源:互联网 发布:新东方网络课程百度云 编辑:程序博客网 时间:2024/06/05 03:00
给出正整数N,请求出N!最右非零的数位的值。
最后,
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>const int MAXN = 1000;int list[25] = {1,1,2,6,4,2,2,4,2,8,4,4,8,4,6,8,8,6,8,2};struct bignumber{ int l , n[MAXN]; void ten() { for(int i = 1; i < l ;i++)n[i] = n[i+1]; n[l--] = 0; } void two() { for(int i = 1 ; i <= l ; i++)n[i] <<= 1; for(int i = 1 ; i <= l ; i++){n[i+1]+=n[i]/10,n[i]%=10;} l += (n[l+1])?1:0; }}num;char ch[MAXN] = {'\0'};int slove(){ int ans = 1; while (num.l) { ans = ans * list[(num.n[2]&1)*10+num.n[1]] % 10; num.two(); num.ten(); } return ans;}int main(){#ifndef ONLINE_JUDGE freopen("hdu1066.in","r",stdin); freopen("hdu1066.out","w",stdout);#endif while(scanf("%s",ch)!=EOF) { memset(num.n,0,sizeof(num.n));num.l = 0; int len = strlen(ch); for(int i = len-1 ,j = 1 ; i >= 0 ; i--,j++) num.n[j] = ch[i] - '0'; for(int i = len ; i >=1 ; i--) if(num.n[i]){num.l = i;break;} printf("%d\n",slove()); }#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif }
0 0
- hdu 1066
- hdu 1066 数学相关
- hdu 1066 数论+递归
- HDU 1066敌兵布阵
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- 单例模式
- ios开发-OC核心语法的学习-1
- EL
- CSDN markdown 编辑器 第五篇 UML
- MySQL权限管理
- hdu 1066
- Xcode6.1 模拟器路径
- 像狗一样奔跑
- Object - C运行时应用(三)——实现NSCoding的自动归档和自动解档
- [Leetcode] 43. Multiply Strings
- 【LeetCode】 sort list 单链表的归并排序
- Android实现可拖拽的ListView
- Chrome development tools学习笔记(3)
- 大写转换成小写