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=;
scanf("%d%d",&n,&b);
for(int i=;i<=n;i++)
{
f*=i;
while(f%b==)
f/=b;
f%=b;
}
printf("%d",f);
return ;
}
最新文章
- web端功能测试总结(一)
- 使用kvm虚拟出Centos6.5系统相关步骤
- 100m和1000m网线的常见制作方法
- sort()和qsort()方法详解
- IntelliJ IDEA集成svn
- Fedora 下 安装 chrome
- CentOS6.5配置MySQL主从同步
- Golang,用map写个单词统计器
- 并查集hdu1232
- Object -C NSNumber -- 笔记
- JavaScript中var a=b=c=d的小发现
- Leetcode::JumpGame
- Delphi @ # $ 特殊字符含义
- springmvc上传图片,发送邮件
- tkinter模块常用参数(python3)
- 天地图使用过程中由于display:none导致加载部分地图瓦片失败
- 平述factory reset	——从main system到重引导流程
- Lightgbm 随笔
- linux挂载硬盘分区
- 基于MFC的socket编程
热门文章
- vs 2017注册码 激活码
- Java之final、static关键字及匿名对象
- jQuery1.6.1源码分析系列(作者:nuysoft/高云)
- {ubuntu}乱七八糟重命名为1 2 3.....png
- 最小化安装centos后ifconfig看不到eth0
- HDU 4274 Spy&#39;s Work (树形DP,模拟)
- 洛谷 P3183 [HAOI2016]食物链
- UVA 11374 Airport Express (最短路)
- 虚拟DOM -------- 最易理解的解释
- jQuery中ready方法的实现