描述
One afternoon as the cows were chewing their cud, Bessie said, "Let's have a contest to see who is the smartest cow. Here's the contest: we will choose a positive number N (no larger than 2,000,000) and whoever computes the rightmost non-zero digit of N factorial will be crowned the smartest cow."
The other cows demurred, however, mooing, "We did that last year."
"Oh," said Bessie, "but there's a catch. We're not necessarily going to use base 10. I know my hooves don't have that many digit
#include<stdio.h>
int main()
{
int n,b,f=1,i;
scanf("%d %d",&n,&b);
for(i=2;i<=n;i++)
{
f*=i;
while(f%b==0)
f/=b;
f%=b;
}
printf("%d",f);
return 0;
}