CF1114C.Trailing Loves (or L'oeufs?)
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number 9200 has two trailing zeros. Aki thinks the more trailing zero digits a number has, the prettier it is.
However, Aki believes, that the number of trailing zeros of a number is not static, but depends on the base (radix) it is represented in. Thus, he considers a few scenarios with some numbers and bases. And now, since the numbers he used become quite bizarre, he asks you to help him to calculate the beauty of these numbers.
Given two integers n and b (in decimal notation), your task is to calculate the number of trailing zero digits in the b-ary (in the base/radix of b) representation of n! (factorial of n).
数字“零”被称为“爱”(更准确地说是法语中的“l'oeuf”,字面意思是“蛋”),例如在网球比赛中表示零分时。
Aki 非常喜欢数字,尤其是那些末尾带有零的数字。例如,数字 9200 有两个末尾零。Aki 认为,一个数字末尾零的个数越多,它就越漂亮。
然而,Aki 相信,一个数字末尾零的个数并非固定不变,而是取决于该数字所采用的进制(基数)。因此,他考虑了若干涉及特定数字与进制的情形。现在,由于他所用的数字变得相当奇特,他请你帮他计算这些数字的“美丽值”。
给定两个十进制整数 n 和 b,你的任务是计算 n!(即 n 的阶乘)在 b 进制(以 b 为基数)表示下的末尾零的个数。
输入格式
The only line of the input contains two integers n and b (1≤n≤1018, 2≤b≤1012).
输入仅包含一行,其中有两个整数 n 和 b(1≤n≤1018,2≤b≤1012)。
输出格式
Print an only integer — the number of trailing zero digits in the b-ary representation of n!
输出一个整数——即 n! 的 b-进制表示中末尾零的个数。
输入输出样例
输入#1
6 9
输出#1
1
输入#2
38 11
输出#2
3
输入#3
5 2
输出#3
3
输入#4
5 10
输出#4
1
说明/提示
In the first example, 6!(10)=720(10)=880(9).
In the third and fourth example, 5!(10)=120(10)=1111000(2).
The representation of the number x in the b-ary base is d1,d2,…,dk if x=d1bk−1+d2bk−2+…+dkb0, where di are integers and 0≤di≤b−1. For example, the number 720 from the first example is represented as 880(9) since 720=8⋅92+8⋅9+0⋅1.
You can read more about bases here.
在第一个例子中,6!(10)=720(10)=880(9)。
在第三个和第四个例子中,5!(10)=120(10)=1111000(2)。
若数 x 在 b 进制下的表示为 d1,d2,…,dk,则满足 x=d1bk−1+d2bk−2+…+dkb0,其中 di 为整数,且 0≤di≤b−1。例如,第一个例子中的数 720 表示为 880(9),因为 720=8⋅92+8⋅9+0⋅1。
关于进制的更多信息,请参阅此处。
输入解题思路,AI测评打分。不知道怎么写?