%5==0)
{
cnt5++;
t=t/5;
}
table[0][i]=table[0][i-1]+cnt2; // 因子2的个数
table[2][i]=table[2][i-1]+cnt5; // 因子5的个数
table[1][i]=table[1][i-1]; // 末位数字为3的个数
table[3][i]=table[3][i-1]; // 末位数字为7的个数
table[4][i]=table[4][i-1]; // 末位数字为9的个数
if (t%10!=1)
table[(t%10-1)/2][i]++;
}
while (cin>>n)
{
cnt2=table[0][n]-table[2][n];
if (cnt2==0)
cnt2 = 1;
else
cnt2=last[0][cnt2%4];
cnt3=last[1][table[1][n]%4];
cnt7=last[2][table[3][n]%4];
cnt9=last[3][table[4][n]%4];
printf("%5d -> %d\n", n, cnt2 * cnt3 * cnt7 * cnt9 % 10);
}
return 0;
}
【例2】The Last Non-zero Digit (POJ 1150)
Description
In this problem you will be given two decimal integer number N, M. You will have to find the last non-zero digit of the P(N,M).This means no of permutations of N things taking M at a time.
Input
The input contains several lines of input. Each line of the input file contains two integers N (0 <= N<= 20000000), M (0 <= M <= N).
Output
For each line of the input you should output a single digit, which is the last non-zero digit of P(N,M). For example, if P(N,M) is 720 then the last non-zero digit is 2. So in this case your output should be 2.
Sample