1570: Cow Brainiacs 

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<stdio.h>
int main()
{
int n,b,f=;
scanf("%d%d",&n,&b);
for(int i=;i<=n;i++)
{
f*=i;
while(f%b==)
f/=b;
f%=b;
}
printf("%d",f);
return ;
}

最新文章

  1. web端功能测试总结(一)
  2. 使用kvm虚拟出Centos6.5系统相关步骤
  3. 100m和1000m网线的常见制作方法
  4. sort()和qsort()方法详解
  5. IntelliJ IDEA集成svn
  6. Fedora 下 安装 chrome
  7. CentOS6.5配置MySQL主从同步
  8. Golang,用map写个单词统计器
  9. 并查集hdu1232
  10. Object -C NSNumber -- 笔记
  11. JavaScript中var a=b=c=d的小发现
  12. Leetcode::JumpGame
  13. Delphi @ # $ 特殊字符含义
  14. springmvc上传图片,发送邮件
  15. tkinter模块常用参数(python3)
  16. 天地图使用过程中由于display:none导致加载部分地图瓦片失败
  17. 平述factory reset ——从main system到重引导流程
  18. Lightgbm 随笔
  19. linux挂载硬盘分区
  20. 基于MFC的socket编程

热门文章

  1. vs 2017注册码 激活码
  2. Java之final、static关键字及匿名对象
  3. jQuery1.6.1源码分析系列(作者:nuysoft/高云)
  4. {ubuntu}乱七八糟重命名为1 2 3.....png
  5. 最小化安装centos后ifconfig看不到eth0
  6. HDU 4274 Spy&#39;s Work (树形DP,模拟)
  7. 洛谷 P3183 [HAOI2016]食物链
  8. UVA 11374 Airport Express (最短路)
  9. 虚拟DOM -------- 最易理解的解释
  10. jQuery中ready方法的实现