#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define MOD 19940417
#define N 100100
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
struct node
{
  int l,r,v;
  bool operator<(const node &A)const
  {
    return r<A.l;
  }
  bool operator==(const node &A)const
  {
    return l==A.l&&r==A.r;
  }
};
LL n,m;
struct arr
{
  int len;
  node a[N];
}t,tn,t1,t2;
LL r1[N],r2[N],v1[N],v2[N];
arr solve(int n)
{
  t.len=0;
  int r=(int)sqrt(n),i;
  FOR(i,1,r)
  {
    t.a[++t.len].r=n/i;t.a[t.len].l=n/(i+1)+1;
    t.a[t.len].v=i;
  }
  FOR(i,1,r)
  {
    ++t.len;
    t.a[t.len].l=t.a[t.len].r=i;
    t.a[t.len].v=n/i;
  }
  sort(t.a+1,t.a+1+t.len);
  node *p=unique(t.a+1,t.a+1+t.len);
  t.len=p-t.a-1;
  return t;
}
LL sss(int x)
{
  if (x==0) return 0;
  LL t1=x,t2=x+1;
  if (t1&1) t2/=2;else t1/=2;
  return t1*t2%MOD;
}
LL sum(LL L,LL R)
{
  return (sss(R)-sss(L-1)+MOD)%MOD;
}
LL ss(LL x)
{
  if (x==0) return 0ll;
  LL t1=x,t2=x+1,t3=2*x+1;
  if (t1%2==0) t1/=2;
  else if (t2%2==0) t2/=2;
  if (t1%3==0) t1/=3;
  else if (t2%3==0) t2/=3;
  else if (t3%3==0) t3/=3;
  return t1*t2%MOD*t3%MOD;
}
LL sum2(LL L,LL R)
{
  return (ss(R)-ss(L-1))%MOD;
}
LL s(LL n,LL limit)
{
  t1=solve(n);
  LL tot=0;int i,R;
  FOR(i,1,t1.len)
  {
    if (t1.a[i].r>=limit) R=limit;else R=t1.a[i].r;
    tot+=t1.a[i].v*sum(t1.a[i].l,R)%MOD;
    tot%=MOD;
    if (t1.a[i].r>=limit) break;
  }
  return tot;
}
LL s1(LL n)
{
  return n*n%MOD-s(n,1e9);
}
LL s2(int n,int m)
{
  memset(t1.a,0,sizeof(t1.a));
  memset(t2.a,0,sizeof(t2.a));
  t1=solve(n);t2=solve(m);int i,j,lst;
  FOR(i,1,t1.len)
  {
    r1[i]=t1.a[i].r+1;
    v1[i-1]=t1.a[i].v;
  }
  FOR(i,1,t2.len)
  {
    r2[i]=t2.a[i].r+1;
    v2[i-1]=t2.a[i].v;
  }
  i=0,j=0,lst=1;
  LL res=0;
  for(;i<=t1.len&&j<=t2.len;)
  {
    if (r1[i+1]<r2[j+1]) 
    {
      res+=sum2(lst,r1[i+1]-1)*v1[i]%MOD*v2[j]%MOD;
      res%=MOD;
      lst=r1[i+1];i++;
    }else
    if (r1[i+1]>=r2[j+1])
    {
      res+=sum2(lst,r2[j+1]-1)*v1[i]%MOD*v2[j]%MOD;
      res%=MOD;
      lst=r2[j+1];j++;
      if (r1[i+1]==r2[j]) i++;
    }
  }
  return res;
}
int main()
{
  scanf("%lld%lld",&n,&m);
  if (n>m) {int t=m;m=n;n=t;}
  int i;
  LL sn=s1(n),sm=s1(m);
  LL r2=sn*sm%MOD;
  r2-=n*m%MOD*n%MOD;
  r2+=n*s(m,n)%MOD+m*s(n,1e9)%MOD;
  r2-=s2(n,m);r2%=MOD;
  printf("%lld\n",(r2+MOD)%MOD);
}