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 ;
}

TOJ 假题之 Cow Brainiacs的更多相关文章

  1. HDU 2147--HDU 2147(博弈)--我可能做了假题。。。

    kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others) Total Su ...

  2. 【USACO】Cow Brainiacs

    题意描述 Cow Brainiacs 求 \(n!\) 在 \(b\) 进制表示下的第一位非 \(0\) 位的数字. 算法分析 闲话 忙人自动略过 之前做过一道 \(10\) 进制表示下的题目,感觉差 ...

  3. 杭电15题 The Cow Lexicon

    Problem Description Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, eac ...

  4. Cow Brainiacs

    #include<stdio.h> int main() { ,i; scanf("%d %d",&n,&b); ;i<=n;i++) { f*= ...

  5. TOJ 4008 The Leaf Eaters(容斥定理)

    Description As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, eat ...

  6. Magic Master(2019年南昌网络赛E题+约瑟夫环)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 初始时你有\(n\)张牌(按顺序摆放),每一次操作你将顶端的牌拿出,然后按顺序将上面的\(m\)张牌放到底部. 思路 首先我们发下拿走\(1\ ...

  7. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

随机推荐

  1. mongodb备份、还原

    1.mongodb  备份 mongodump 命令可以使用可用的选项的列表. 此命令将仅备份指定的数据库,在指定的路径 语法 描述 示例 mongodump --host HOST_NAME --p ...

  2. 解决spring http输入流和输出流只能读取一次

    1.需求:给某些请求接口记录日志,记录请求的数据和响应的数据和请求所花费的时间.这里采用非侵入式编程,也业务代码进行解耦.按照spring AOP 的编程思想. 2.编程设计:在spring 拦截器中 ...

  3. Easyui combobox如何默认选中第一项???

    以下代码可以实现combobox默认选中第一项,在实际开发中我们可能会用到! // 处理combobox默认选中的问题 <input id="user_type" class ...

  4. Ubuntu下软件的搜索与安装

    本文为笔者原创,首发于简书(点击这里查看). 小白玩转linux的第一个拦路虎就是软件的安装了.本文结合自己在Ubuntu14.04下软件安装经验做一个总结. 1.如何搜索软件? apt-cache ...

  5. Android学习总结(四)—— Activity和 Service进行通信

    一.Activity 和 Service进行通信的基本概念 前面我们学习我生命周期里面包含了启动和停止服务的方法,虽然服务器在活动里启动,但在启动了服务之后,活动与服务基本就没有什么关系了.我们在活动 ...

  6. hihoCoder #1068 : RMQ-ST算法(模板)

    AC G++ 826ms 146MB 思路: 时间复杂度O(nlogn). //#include <bits/stdc++.h> #include <iostream> #in ...

  7. codevs 1145 Hanoi双塔问题 2007年NOIP全国联赛普及组

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 给定A.B.C三根足够长的细柱,在A柱上放有2n个中间有孔的圆盘,共有n个不同的 ...

  8. OCR/Vote disk 维护操作: (添加/删除/替换/移动) (文档 ID 1674859.1)

    适用于: Oracle Database - Enterprise Edition - 版本 10.2.0.1 到 11.2.0.1.0 [发行版 10.2 到 11.2]本文档所含信息适用于所有平台 ...

  9. 从汇编看c++中的多态

    http://www.cnblogs.com/chaoguo1234/archive/2013/05/19/3079078.html 在c++中,当一个类含有虚函数的时候,类就具有了多态性.构造函数的 ...

  10. 二. python函数与模块

    第四章.内置函数与装饰器详解 1.内置函数补充1 注:红色圆圈:必会:  紫红色方框:熟练:   绿色:了解 callable() 判断函数是否可以被调用执行 def f1(): pass f1() ...