为什么一分不得
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e6;
//const int mod=1e9+7;
typedef long long ll;
namespace io{
const int _SIZE=(1<<21)+1;
char ibuf[_SIZE],*iS,*iT,c,stk[40];int tot;
#define gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,_SIZE,stdin),(iS==iT ?EOF:*iS++)):*iS++)
template<class I>
inline void read(I &_x){
I fl=1;
for(c=gc();c<'0'||c>'9';c=gc()) if(c=='-') fl=-1;
for(_x=0;c>='0'&&c<='9';c=gc()) _x=_x*10+(c&15);
_x*=fl;
}
template<class I>
inline void prt(I _x,char ch='\0'){
tot=0;
if(_x<0) putchar('-'),_x*=-1;
do{
stk[tot++]=_x%10|48;_x/=10;
}while(_x);
do{
putchar(stk[--tot]);
}while(tot);
if(ch)putchar(ch);
}
}
using io::read;
using io::prt;
inline int rd(){
static int x;int f=1;
static char c;
while((c=getchar())<'0'||c>'9') if(c=='-') f=-1;
x=(c&15);
while((c=getchar())>='0'&&c<='9') x=(x<<3)+(x<<1)+(c&15);
return x*f;
}
ll n,p;
ll ans,mod;
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
int main(){
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
read(n),read(p);mod=p;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ans+=(i%mod)*(j%mod)*(gcd(i,j)%mod)%mod;
}
}
prt(ans);
return 0;
}