#include<bits/stdc++.h>
#define int long long
#define cint const int
#define uint unsigned int
#define cuint const unsigned int
#define ll long long
#define cll const long long
#define ull unsigned long long
#define cull const unsigned long long
#define sh short
#define csh const short
#define ush unsigned short
#define cush const unsigned short
using namespace std;
ll read()
{
ll x=0;
char ch=getchar();
while(ch<'0'||ch>'9')
{
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch-'0');
ch=getchar();
}
return x;
}
void print(cll x)
{
if(x<10)
{
putchar(x+'0');
return;
}
print(x/10);
putchar(x%10+'0');
}
void princh(cll x,const char ch)
{
print(x);
putchar(ch);
}
int mod,iv2;
inline int M(cll x)
{
return (x>=mod?x-mod:x);
}
int qpow(cint x,cint y)
{
if(y==0)return 1;
cint t=qpow(x,y>>1);
if(y&1)return 1ll*t*t%mod*x%mod;
return 1ll*t*t%mod;
}
cint V=5e7;
bool flag[V+1];
vector<int>prime;
signed phi[V+1],s[V+1];
void init()
{
phi[1]=s[1]=1;
for(int i=2;i<=V;++i)
{
if(!flag[i])
{
prime.push_back(i);
phi[i]=i-1;
}
for(int p:prime)
{
if(1ll*i*p>V)return;
flag[i*p]=1;
if(i%p==0)
{
phi[i*p]=phi[i]*p;
break;
}
phi[i*p]=phi[i]*(p-1);
}
s[i]=(1ll*phi[i]*i%mod*i+s[i-1])%mod;
}
}
unordered_map<ll,int>mp;
int sum4(cll n)
{
int res=n%mod*((n+1)%mod)%mod*iv2%mod;
res=1ll*res*res%mod;
return res;
}
int S(cll n)
{
if(n<=V)return s[n];
if(mp.count(n))return mp[n];
ll res=sum4(n);
for(ll l=2,r;l<=n;l=r+1)
{
r=n/(n/l);
res=M(res+mod-(r-l+1)%mod*S(n/l)%mod);
}
return (mp[n]=res);
}
signed main()
{
mod=read();
iv2=(mod+1>>1);
init();
cll n=read();
int ans=0;
for(ll l=1,r;l<=n;l=r+1)
{
r=n/(n/l);
ans=(1ll*sum4(n/l)*(S(r)-S(l-1)+mod)+ans)%mod;
}
print(ans);
return 0;
}