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. StarUML安装与Win7不兼容解决

    最近在学习建模工具(StarUML)发现 其他功能一切正常 但是无法显示代码导出功能, 正常界面如下: 我的安装确没有导出功能缺少C++,C# ,Java等导出功能 解决办法:     到StarUM ...

  2. js作用域及对象以及一些常用技巧

    回顾 流程控制(语句) 分支 if () {    }​if () {    } else {    }​if () {    } else if () {    } else if () {     ...

  3. 4、重建二叉树------------>剑指offer系列

    题目1-二叉树重建 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字. 例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序 ...

  4. 使用python模拟cookie登陆wooyun

    import urllib2 class SimpleCookieHandler(urllib2.BaseHandler): def http_request(self, req): simple_c ...

  5. 多源最短路径floyd

    #include<iostream> #define INF 105 using namespace std; int main() { ][],mark,x,y,g; while(cin ...

  6. C# Process.Start方法

    System.Diagnostics.Process.Start(); 主要功能: 1.打开某个链接网址(弹窗). 2.定位打开某个文件目录. 3.打开系统特殊文件夹,如“控制面板”等. Proces ...

  7. Vue+webpack+echarts+jQuery=demo

    需要的插件: "dependencies": { "bootstrap": "^3.3.7", "echarts": & ...

  8. vue的使用-项目总结

    1,这是一个重前端逻辑,轻交互,数据展示的项目,可读性差,2,组件划分的坑,复用过多的坑,复用过多导致要在js手动判断太多东西,不便于可读3,vuex的坑,数据分为后台请求数据的暂存,前端页面逻辑的状 ...

  9. ndarray数组变换

    import numpy as np 维度变换 a = np.arange(24) a array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ...

  10. Java多线程大合集

    1) 什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成 ...