import java.util.*; public class Main{ static final int MOD = 1000000007; public static void main(String args[]){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int P = sc.nextInt(); int primes[] = new int[1000]; int primeNum = 1; primes[0] = 2; for(int i = 3; i < 1000; i++){ boolean isPrime = true; for(int j = 0; j < primeNum; j++){ if(i % primes[j] == 0){ isPrime = false; break; } } if(isPrime){ primes[primeNum] = i; primeNum++; } } int dum = P; int dividePrime[] = new int[primeNum+1]; int productPrime[] = new int[primeNum+1]; for(int i = 0; i < primeNum; i++){ dividePrime[i] = 0; productPrime[i] = 1; while(dum % primes[i] == 0){ dividePrime[i]++; productPrime[i] *= primes[i]; dum /= primes[i]; } } if(dum != 1){ primes[primeNum] = dum; dividePrime[primeNum] = 1; productPrime[primeNum] = dum; primeNum++; } int maxProdInd = 0; for(int i = 0; i < primeNum; i++){ if(productPrime[maxProdInd] < productPrime[i]){ maxProdInd = i; } } int maxPrime = primes[maxProdInd]; int divide = dividePrime[maxProdInd]; // System.out.println("["+maxPrime+","+divide+"]"); if(maxPrime > N){ System.out.println(0); return; } Long numP = 0l; for(int i = 1; i <= N; i++){ int n = i; while(n % maxPrime == 0){ numP++; n /= maxPrime; } } long amariP = numP % divide; numP /= divide; // System.out.println("["+numP+","+amariP+"]"); long nM = 1; long amariNM = 1; for(int i = 1; i <= N; i++){ if(i != divide){ amariNM *= i; } nM *= i; nM %= MOD; amariNM %= MOD; } // System.out.println(nM); long divideInv; { long a = divide; long b = MOD; long u = 1; long v = 0; while (b != 0) { long t = a / b; a -= t * b; long dummy = a; a = b; b = dummy; u -= t * v; dummy = u; u = v; v = dummy; } u %= MOD; if (u < 0) u += MOD; divideInv = u; } char[] S = Long.toBinaryString(nM).toCharArray(); long binM = nM; long ans = 1; for(int i = S.length-1; i >= 0; i--){ // System.out.print(S[i]); if(S[i] == '1'){ ans *= binM; ans %= MOD; } binM *= binM; binM %= MOD; } // System.out.println(); long amariAns = ans * amariP; amariAns %= MOD; amariAns *= divideInv; amariAns %= MOD; // System.out.println(amariAns); ans *= numP; ans %= MOD; // System.out.println(ans); ans += amariAns; ans %= MOD; System.out.println(ans); } }