No.644 G L C C D M
タグ : / 解いたユーザー数 59
作問者 :
Pulmn
/ テスター :
Problem Statement
Find the number of permutations $A$ of $(1,2,\dots,N)$ that satisfy the following condition. Since this value can be very large, output the remainder when it is divided by $1{,}000{,}000{,}007$.
Condition: when the following operation is performed $N-1$ times on $A$, $A_1=M$ holds.
Let $B$ be the sequence after the operation.
Operation: The length of the sequence $B$ is $( A の長さ) - 1$, and for every $i$ satisfying $1\le i\le (Aの長さ)-1$,
$$ \begin{aligned}\ B_i=\begin{cases}gcd(A_i,A_{i+1})&(iが奇数) \\ lcm(A_i,A_{i+1})&(iが偶数) \end{cases}\end{aligned} $$
holds.
Here, $gcd(x,y)$ denotes the greatest common divisor of $x$ and $y$, and $lcm(x,y)$ denotes the least common multiple of $x$ and $y$.
Input
$N$ $M$
$2\le N\le 10^5,1\le M\le 10^9$
Output
Output the number of permutations $A$ satisfying the condition, modulo $1{,}000{,}000{,}007$. Print a newline at the end.
Sample
Sample 1
Input
3 1
Output
6
All permutations of $(1,2,3)$ satisfy the condition. For example, when $A=\{3,1,2\}$:
After operation $1$: $A=\{gcd(3,1),lcm(1,2)\}=\{1,2\}$
After operation $2$: $A=\{gcd(1,2)\}=\{1\}$
Sample 2
Input
2 1
Output
2
Sample 3
Input
3 100
Output
0
When the operation is performed $2$ times on a permutation $A$ of $(1,2,3)$, $A_1=1$ always holds, so the number of permutations satisfying the condition is $0$.
Sample 4
Input
100 30
Output
945719957
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。