#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb push_back
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD= 1e9+7 ;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}

bool compare(string a, string b){
	if(a.length()==b.length())
		return a<b;
	return a.length()<b.length();
}
const int sz = 1e5;
ll fact[sz], inv[sz];
void pre(){
	fact[0]=1;
	for(int i=1;i<sz;i++){
		fact[i] = (fact[i-1] * i)%MOD;
	}
	for(int i=0;i<sz;i++){
		inv[sz] = powerMod(fact[i], MOD-2);
	}
}
int main()
{
    fast;
    pre();
    int t;
    t = 1;
    //~ cin>>t;
    
    while(t--){
		ll n,k;
		cin>>n>>k;
		//~ cout<<endl<<"CHECKER"<<endl<<endl;
		
		//~ map<ll,ll> mp;
		//~ for(int i=1;i<=k;i++){
			//~ for(int j=1;j<=k;j++){
				//~ for(int l=1;l<=k;l++){
					//~ mp[__gcd(i, __gcd(j,l))]++;
					//~ if(__gcd(i, __gcd(j,l))==2){
						//~ cout<<i<<" "<<j<<" "<<l<<endl;
					//~ }
				//~ }
			//~ }
		//~ }
		
		ll ans = 0, ways = 0;
		map<ll,ll> help;
		for(int i=k;i>=2;i--){
			ll temp = (powerMod(k/i, n)-help[i] + MOD)%MOD;
			for(int j=2;j*j<=i;j++){
				if(i%j==0){
					help[j] = (help[j] + temp)%MOD;
					if(j*j!=i){
						help[i/j] = (help[i/j] + temp)%MOD;
					}
				}
			}
			ans = (ans +  (i)*temp%MOD)%MOD;
			ways = (ways + temp)%MOD;
			
			//~ cout<<i<<" "<<temp<<" "<<mp[i]<<endl;
		}
		//~ error(ways, ans);
		ans = (ans + powerMod(k,n) - ways +MOD)%MOD;
		cout<<ans;
		
		
		
		
	}
    
    return 0;
}


Measured memory_bytes: 10668