#include<bits/stdc++.h> #define maxn 10200006 #define ll long long #define M 10000007 using namespace std; int cnt; ll sumv[maxn], rev4, rev6, mod, rev2; bool vis[maxn]; ll phi[maxn], prime[maxn]; map<ll,ll>ansphi; void setIO(string s) { string in=s+".in"; freopen(in.c_str(),"r",stdin); } ll qpow(ll base, ll k) { ll tmp=1; while(k) { if(k&1) tmp=tmp*base%mod; base=base*base%mod; k>>=1; } return tmp; } void init() { int i,j; rev4=qpow(4ll, mod-2), rev6=qpow(6ll, mod-2), rev2=qpow(2ll, mod-2); phi[1]=1; for(i=2;i<=M;++i) { if(!vis[i]) prime[++cnt]=i, phi[i]=i-1; for(j=1;j<=cnt&&1ll*i*prime[j]<=M;++j) { vis[i*prime[j]]=1; if(i%prime[j]==0) { phi[i*prime[j]]=phi[i]*prime[j]; break; } phi[i*prime[j]]=phi[i]*(prime[j]-1); } } for(i=1;i<=M;++i) sumv[i]=(sumv[i-1]+(1ll*phi[i]*i%mod*i%mod))%mod; } // 平方 ll cal1(ll i) { i%=mod; ll re=i%mod; re=re*(i+1)%mod; re=re*(i+i+1)%mod; re=(re*rev6)%mod; return re; } // 立方 ll cal2(ll i) { i%=mod; ll re=i%mod; re=(re*i)%mod; re=(re*(i+1))%mod; re=re*(i+1)%mod; re=(re*rev4)%mod; return re; } ll get(ll n) { if(n<=M) return sumv[n]; if(ansphi[n]) return ansphi[n]; ll i,j,re=cal2(n),tmp; for(i=2;i<=n;i=j+1) { j=n/(n/i); tmp=(cal1(j)-cal1(i-1)+mod)%mod; tmp=(tmp*get(n/i))%mod; re=(re-tmp+mod)%mod; } return ansphi[n]=re; } ll calc(ll n) { n%=mod; return (((n*(n+1))%mod)*(rev2%mod))%mod ; } int main() { // setIO("input"); ll n,i,j,re=0,tmp=0; scanf("%lld%lld",&mod,&n); init(); for(i=1;i<=n;i=j+1) { j=n/(n/i); tmp=(calc(n/i)*calc(n/i)%mod*(get(j)-get(i-1)+mod)%mod)%mod; re=(re+tmp+mod)%mod; } printf("%lld\n",re); return 0; }