#include<stdio.h>
int get(int x,int n)
{
if(n==0)
return 0;
else
return (n/x)+get(x,n/x);
}
int get1(int x,int n)
{
if(n==0)
return 0;
else
return (n/10)+((n%10)>=x)+get1(x,n/5);
}
int get2(int x,int n)
{
if(n==0)
return 0;
else
return get2(x,n/2)+get1(x,n);
}
int t[3][4]={{6,2,4,8},{1,3,9,7},{1,7,9,3}};
int main()
{
int n,m,n2,n3,n5,n7,n9,res=1;
scanf("%d%d",&n,&m);
n2=get(2,n)-get(2,n-m)-get(2,m);
n5=get(5,n)-get(5,n-m)-get(5,m);
n3=get2(3,n)-get2(3,n-m)-get2(3,m);
n7=get2(7,n)-get2(7,n-m)-get2(7,m);
n9=get2(9,n)-get2(9,n-m)-get2(9,m);
n3+=n9*2;
if(n2<n5)
printf("5\n");
else
{
if(n2!=n5)
{
res*=t[0][(n2-n5)%4];
}
res*=t[1][n3%4];
res*=t[2][n7%4];
printf("%d\n",res%10);
}
}
poj 3406 组合数的最后非0数
最新推荐文章于 2017-10-21 16:31:47 发布