cho.sh
Notes
Loading...

Counting Product Subset Coefficients

Time limit

2s

Memory limit

512 MB

Problem

For integers nnn and kkk, let [n]={1,2,…,n}[n]=\{1,2,\dots,n\}[n]={1,2,…,n}. The value f(n,k)f(n,k)f(n,k) is the sum, over every kkk-element subset of [n][n][n], of the product of the elements in that subset. In other words,

[ f(n,k)=\sum_{S\subseteq [n],\ |S|=k}\prod_{x\in S}x. ]

Also, f(n,0)=1f(n,0)=1f(n,0)=1.

Given a positive integer nnn and a prime ppp, count how many integers kkk with 0≤k≤n0\le k\le n0≤k≤n make f(n,k)f(n,k)f(n,k) not divisible by ppp.

Input

The first line contains an integer nnn and a prime ppp, separated by a space.

Output

Print the number of valid values of kkk, modulo 109+710^9+7109+7.

Constraints

  • 1≤n<105011 \le n < 10^{501}1≤n<10501
  • 2≤p≤1052 \le p \le 10^52≤p≤105
  • ppp is prime