問題一覧 > 通常問題

No.644 G L C C D M

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 59
作問者 : Pulmn / テスター : square1001
お気に入りにしたユーザー ProblemId : 1665 / 自分の提出
問題文最終更新日: 2022-04-25 02:19:48
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 182 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。