TOJ 假题之 Cow Brainiacs
Posted BobHuang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TOJ 假题之 Cow Brainiacs相关的知识,希望对你有一定的参考价值。
1570: Cow Brainiacs
Total Submit: 15 Accepted:8
Description
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.
Input
A single line with integers N and B
Output
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".
Sample Input
Sample Output
Hint
#include<stdio.h> int main() { int n,b,f=1; scanf("%d%d",&n,&b); for(int i=2;i<=n;i++) { f*=i; while(f%b==0) f/=b; f%=b; } printf("%d",f); return 0; }
以上是关于TOJ 假题之 Cow Brainiacs的主要内容,如果未能解决你的问题,请参考以下文章
TOJ 1693:Silver Cow Party(最短路+思维)
usaco 过路费 Cow Toll Paths, 2009 Dec