A12448 | Trailing Loves (or L'oeufs?)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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](https://en.wikipedia.org/wiki/Factorial) of $n$ ).
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](https://en.wikipedia.org/wiki/Factorial) of $n$ ).
输入格式
The only line of the input contains two integers $n$ and $b$ ( $1 \le n \le 10^{18}$ , $2 \le b \le 10^{12}$ ).
输出格式
Print an only integer — the number of trailing zero digits in the $b$ -ary representation of $n!$
输入输出样例
输入 #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 $d_1, d_2, \ldots, d_k$ if $x = d_1 b^{k - 1} + d_2 b^{k - 2} + \ldots + d_k b^0$ , where $d_i$ are integers and $0 \le d_i \le b - 1$ . For example, the number $720$ from the first example is represented as $880_{(9)}$ since $720 = 8 \cdot 9^2 + 8 \cdot 9 + 0 \cdot 1$ .
You can read more about bases [here](https://en.wikipedia.org/wiki/Radix).
In the third and fourth example, $5!_{(10)} = 120_{(10)} = 1111000_{(2)}$ .
The representation of the number $x$ in the $b$ -ary base is $d_1, d_2, \ldots, d_k$ if $x = d_1 b^{k - 1} + d_2 b^{k - 2} + \ldots + d_k b^0$ , where $d_i$ are integers and $0 \le d_i \le b - 1$ . For example, the number $720$ from the first example is represented as $880_{(9)}$ since $720 = 8 \cdot 9^2 + 8 \cdot 9 + 0 \cdot 1$ .
You can read more about bases [here](https://en.wikipedia.org/wiki/Radix).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted