博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TOJ 假题之 Cow Brainiacs
阅读量:6271 次
发布时间:2019-06-22

本文共 1521 字,大约阅读时间需要 5 分钟。

1570: Cow Brainiacs 分享至QQ空间

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
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

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.
求n!的k进制下最后一个非0位的数字,我只想喊666
10进制主要有两种,线性模方程的,之后找到考虑hashtable的
这个竟然就是直接暴力的
#include
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;}

 

转载于:https://www.cnblogs.com/BobHuang/p/7533509.html

你可能感兴趣的文章
NC营改增
查看>>
Lua
查看>>
Mysql备份系列(3)--innobackupex备份mysql大数据(全量+增量)操作记录
查看>>
postgresql 获取刚刚插入的数据主键id
查看>>
C# Activex开发、打包、签名、发布 C# Activex开发、打包、签名、发布 [转]
查看>>
05-Vue入门系列之Vue实例详解与生命周期
查看>>
验证码展示
查看>>
浅谈大型web系统架构
查看>>
淘宝大秒系统设计详解
查看>>
linux如何修改登录用户密码
查看>>
Kali Linux 2017中Scapy运行bug解决
查看>>
Python监控进程性能数据并画图保存为PDF文档
查看>>
Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
查看>>
Mac OS 10.10.3下Apache + mod_wsgi配置【一】
查看>>
Hibernate基于注解的双向one-to-many映射关系的实现
查看>>
算法竞赛入门经典 例题 3-2 蛇形填数
查看>>
remove-duplicates-from-sorted-list I&II——去除链表中重复项
查看>>
c++ 网络库
查看>>
Linux 格式化扩展分区(Extended)
查看>>
linux echo命令
查看>>