n!在k进制下的后缀0

问n! 转化成k进制后的位数和尾数的0的个数。【UVA 10061 How many zeros and how many digits?】

Given a decimal integer number you will have to find out how many trailing zeros will be there in its
factorial in a given number system and also you will have to find how many digits will its factorial have
in a given number system? You can assume that for a b based number system there are b different
symbols to denote values ranging from 0 . . . b − 1.
Input
There will be several lines of input. Each line makes a block. Each line will contain a decimal number
N (a 20bit unsigned number) and a decimal number B (1 < B ≤ 800), which is the base of the number
system you have to consider. As for example 5! = 120 (in decimal) but it is 78 in hexadecimal number
system. So in Hexadecimal 5! has no trailing zeros.
Output
For each line of input output in a single line how many trailing zeros will the factorial of that number
have in the given number system and also how many digits will the factorial of that number have in
that given number system. Separate these two numbers with a single space. You can be sure that the
number of trailing zeros or the number of digits will not be greater than 231 − 1.
Sample Input
2 10
5 16
5 10
Sample Output
0 1
0 2
1 3

n! 在k进制下后缀0的个数。【洛谷 一道中档题】

输入输出格式
输入格式:
每组输入仅包含一行:两个整数n,k。

输出格式:
输出一个整数:n!在k进制下后缀0的个数。

输入输出样例
输入样例#1:
10 40
输出样例#1:
2
说明
对于20%的数据,n <= 1000000, k = 10

对于另外20%的数据,n <= 20, k <= 36

对于100%的数据,n <= 10^12,k <= 10^12

  



给出一个k进制的数n,求n!里一共有多少个0。【ZOJ Factorial Problem in Base K】

How many zeros are there in the end of s! if both s and s! are written in base k which is not necessarily to be 10? For general base, the digit order is 0-9,A-Z,a-z(increasingly), for example F4 in base 46 is actually 694 in base 10,and f4 in base 46 is 1890 in base 10.

Input
There are multiple cases(less than 10000). Each case is a line containing two integers s and k(0 ≤ s < 2^63, 2 ≤ k ≤ 62).

Output
For each case, output a single line containing exactly one integer in base 10 indicating the number of zeros in the end of s!.

Sample Input
101 2
12 7
Sample Output
3
1

  

原文地址:https://www.cnblogs.com/Roni-i/p/8797918.html

时间: 2024-10-13 20:27:14

n!在k进制下的后缀0的相关文章

51nod 1116:K进制下的大数

51nod 1116:K进制下的大数 题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1116 题目大意:给定一个大数,该数在$K$进制下是$K-1$的倍数,问最小的$K$($2 \leqslant K \leqslant 36$)是多少,若无解输出No Solution. 二项式定理 这题虽然可以暴力枚举,但还有更优雅的做法. 考虑一个$K$进制的大数$A$可以被表示为$\sum_{x=0}a_xK^x$,

51NOD 1116 K进制下的大数(字符串取模 + 枚举)

传送门 1116 K进制下的大数 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 有一个字符串S,记录了一个大数,但不知这个大数是多少进制的,只知道这个数在K进制下是K - 1的倍数.现在由你来求出这个最小的进制K. 例如:给出的数是A1A,有A则最少也是11进制,然后发现A1A在22进制下等于4872,4872 mod 21 = 0,并且22是最小的,因此输出k = 22(大数的表示中A对应10,Z对应35). Input 输入大数对应的字符串S

light oj 1045 - Digits of Factorial K进制下N!的位数

1045 - Digits of Factorial Factorial of an integer is defined by the following function f(0) = 1 f(n) = f(n - 1) * n, if(n > 0) So, factorial of 5 is 120. But in different bases, the factorial may be different. For example, factorial of 5 in base 8 i

51nod 1116 K进制下的大数 (暴力枚举)

题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; const int MAXS = 1e5 + 10; const int MAXK = 36; char num[MAXS]; int main(int argc, const char * argv[]) { while (cin >> num) { int sum = 0; int len = (int)

light oj 1045 - Digits of Factorial(求阶乘在不同进制下的位数)

Factorial of an integer is defined by the following function f(0) = 1 f(n) = f(n - 1) * n, if(n > 0) So, factorial of 5 is 120. But in different bases, the factorial may be different. For example, factorial of 5 in base 8 is 170. In this problem, you

快速沃尔什变换与k进制FWT

这是一篇用来卖萌的文章QAQ 考虑以下三类卷积 \(C_k = \sum \limits_{i \;or\;j = k} A_i * B_j\) \(C_k = \sum \limits_{i\;and\;j = k} A_i * B_j\) \(C_k = \sum \limits_{i\;xor\;j = k}A_i * B_j\) 由于前两种可以用FMT(高维前缀和)解决,那我们就谈谈第三种吧 下文中的\(n\)都是形如\(2^i - 1\)的数 下标的开与闭是根据好不好写来定的,但是还是

c++ k进制Huffman树

原址:http://blog.csdn.net/Quack_quack/article/details/46958413 题目大意:给出n个数字w[],代表n个字母出现的次数,给出k.要求用k进制的数字串si替换第i个字母,且替换之后要求替换后的文章无二义性(这里的无二义性是指对于任意的 1≤i,j≤n ,i≠j,都有: si不是sj的前缀),求替换后最短的文章的长度(长度len=sigma(w[i]*strlen(si)))和这种情况下最大的si的最小值. 数据范围:n<=100000,k<

假设数n在b进制下为回文数,求最小的b

题目链接:here 假设n=b0+b1+b2....+bk 如果b2<=n,那么那么n在b进制下有多个数组成,可以直接暴力算 如果暴力没有正确的结果,即: 如果b2>n,那么n在b进制下只有两个数组成 要组成回文树,则xb+x=n  b=n/x-1 ,(n%x==0,x<b),要求b最小,则使x最大, 从sqrt(n+1)开始枚举x即可 #include<iostream> #include<cstdio> #include<cmath> using

[luogu]P1066 2^k进制数[数学][递推][高精度]

[luogu]P1066 2^k进制数 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后,则q的总位数不超过w. 在这里,正整数k(1≤k≤9)和w(k<W≤30000)是事先给定的. 问:满足上述条件的不同的r共有多少个? 我们再从另一角度作些解释:设S是长度为w 的01字符串(即字符串S由w个“0”或“1”组成),S对应于上述条件(3)中的q