问题1684--【USACO】Cow Brainiacs

1684: 【USACO】Cow Brainiacs

时间限制: 1 Sec  内存限制: 64 MB
提交: 8  解决: 5
[提交] [状态] [讨论版] [命题人:]

题目描述

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 digits! We'll just specify a positive number base B from 2 through 30." Write a program to help the cows judge their intelligence contest.

输入

A single line with integers N and B

输出

A single line with the decimal-representation of the "digit" that is the rightmost non-zero digit for N! in base B. If B > 10, go ahead and output a two-digit decimal number as a representation of the final "digit".

样例输入 复制

13 3

样例输出 复制

2

提示

ABOUT SAMPLE OUTPUT: [13*12*11*10*9*8*7*6*5*4*3*2*1=6227020800 base 10, which in base 3 is 121001222020102200000, so the right-most non-zero digit is 2.]

来源/分类


[提交] [状态]