#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) moC(res, *, x);
    moC(x, *, x);
    n>>=1;
  }
  return res;
}

map<ll, ll> prm;
void factrization(ll n) {
  for(ll i=2; i*i<=n; i++) {
    while(n%i==0) {
      prm[i]++;
      n/=i;
    }
  }
  
  if(n>1) prm[n]++;
}

map<ll, ll> mp;
void divisor(ll n) {
  for(ll i=1; i*i<=n; i++) {
    if(n%i==0) {
      mp[i]++;
      mp[n/i]++;
    }
  }
}

int main() {
  ll i, j, k;
  
  ll N, K;
  cin >> N >> K;
  
  divisor(K);
  ll ans=0;
  for(auto it=mp.begin(); it!=mp.end(); it++) {
    ll t=it->ft;
    
    prm.clear();
    factrization(K/t);
    ll cnt=1;
    for(auto jt=prm.begin(); jt!=prm.end(); jt++) {
      moC(cnt, *, (moP(jt->sc+1, N)-moP(jt->sc, N)+MOD)%MOD);
    }
    
    
    
    moC(ans, +, t*cnt);
    
  }
  
  pt(ans);
}


