来源http://acm.hdu.edu.cn/showproblem.php?pid=1066
讲解:http://www.cnblogs.com/Lyush/archive/2012/08/10/2631545.html
参考别人代码写的,自己分析这种问题的能力真是为负。。。
加油加油!
#include<stdio.h>
#include<math.h>
#include<string>
using namespace std;
int tb[20]={1,1,2,6,4,2,2,4,2,8,4,4,8,4,6,8,8,6,8,2};//20为一个循环
char s[1000];
int a[1000];
int main()
{
while(~scanf("%s",s))
{
int len,i,j,temp=1,r,temp1;
len=strlen(s);
memset(a,0,sizeof(a));j=0;
for(i=len-1;i>=0;i--,j++)
a[j]=s[i]-'0';
while(len)
{
len-=!a[len-1];//下面除以5的操作可能会让首位为0
temp=temp*tb[a[1]%2*10+a[0]];
r=0;
for(i=len-1;i>=0;i--)
{
temp1=r*10+a[i];
a[i]=temp1/5;
r=temp1%5;
}
}
printf("%d\n",temp);
}
return 0;
}