#include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<utility> #include<set> #include<bitset> #include<vector> #include<functional> #include<deque> #include<cctype> #include<climits> #include<complex> using namespace std; typedef long long LL; typedef double DB; typedef pair<int,int> PII; typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a)) #define mmcy(a,b) memcpy(a,b,sizeof(a)) #define re(i,a,b) for(i=a;i<=b;i++) #define red(i,a,b) for(i=a;i>=b;i--) #define fi first #define se second #define m_p(a,b) make_pair(a,b) #define SF scanf #define PF printf #define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;} template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;} template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-9; inline int sgn(DB x){if(abs(x)<EPS)return 0;return(x>0)?1:-1;} const DB Pi=acos(-1.0); inline int gint() { int res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z=='-'){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar()); return (neg)?-res:res; } inline LL gll() { LL res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z=='-'){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar()); return (neg)?-res:res; } const LL maxN=10000000LL; const LL Mod=20101009LL; LL N,M; LL ans; LL mu[maxN+100],sum[maxN+100]; LL prime[maxN+100],tol; bool isnotprime[maxN+100]; inline void prepare() { LL i,j; mu[1]=1; re(i,2,N) { if(!isnotprime[i]){mu[i]=-1;prime[++tol]=i;} for(j=1;j<=tol && prime[j]*i<=N;j++) { isnotprime[prime[j]*i]=1; if(i%prime[j]==0){mu[prime[j]*i]=0;break;} mu[prime[j]*i]=-mu[i]; } } re(i,1,N) sum[i]=(sum[i-1]+(mu[i]*i*i)%Mod)%Mod; } inline LL F(LL x,LL y) { LL res=0,e,last; for(e=1;e<=x;e=last+1) { last=min(x/(x/e),y/(y/e)); upmin(last,x); LL s=(sum[last]-sum[e-1])%Mod; LL t=((1+(x/e))*(x/e)/2%Mod)*((1+(y/e))*(y/e)/2%Mod)%Mod;//记住要多加括号 res=(res+s*t%Mod)%Mod; } return res; } int main() { freopen("bzoj2154.in","r",stdin); freopen("bzoj2154.out","w",stdout); N=gll();M=gll(); if(N>M)swap(N,M); prepare(); ans=0; LL d,last; for(d=1;d<=N;d=last+1) { last=min(N/(N/d),M/(M/d)); upmin(last,N); LL s=(d+last)*(last-d+1)/2%Mod; LL t=F(N/d,M/d); ans=(ans+s*t%Mod)%Mod; } ans=(ans%Mod+Mod)%Mod; cout<<ans<<endl; return 0; }
#include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #include<algorithm> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<map> #include<utility> #include<set> #include<bitset> #include<vector> #include<functional> #include<deque> #include<cctype> #include<climits> #include<complex> using namespace std; typedef long long LL; typedef double DB; typedef pair<int,int> PII; typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a)) #define mmcy(a,b) memcpy(a,b,sizeof(a)) #define re(i,a,b) for(i=a;i<=b;i++) #define red(i,a,b) for(i=a;i>=b;i--) #define fi first #define se second #define m_p(a,b) make_pair(a,b) #define SF scanf #define PF printf #define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;} template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;} template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-9; inline int sgn(DB x){if(abs(x)<EPS)return 0;return(x>0)?1:-1;} const DB Pi=acos(-1.0); inline int gint() { int res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z=='-'){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar()); return (neg)?-res:res; } inline LL gll() { LL res=0;bool neg=0;char z; for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar()); if(z==EOF)return 0; if(z=='-'){neg=1;z=getchar();} for(;z!=EOF && isdigit(z);res=res*10+z-'0',z=getchar()); return (neg)?-res:res; } const LL Mod=20101009LL; const LL maxN=10000000LL; LL N,M; LL f[maxN+100]; LL prime[maxN+100],tol; bool isnotprime[maxN+100]; inline void prepare() { f[1]=1; LL i,j; re(i,2,N) { if(!isnotprime[i]){prime[++tol]=i;f[i]=1-i;} for(j=1;j<=tol && i*prime[j]<=N;j++) { isnotprime[i*prime[j]]=1; if(i%prime[j]==0) { f[i*prime[j]]=f[i]; break; } f[i*prime[j]]=f[i]*f[prime[j]]%Mod; } } } int main() { freopen("bzoj2154.in","r",stdin); freopen("bzoj2154.out","w",stdout); LL i; N=gll();M=gll(); if(N>M)swap(N,M); prepare(); LL ans=0; re(i,1,N) { LL res=i; res=res*((1+(N/i))*(N/i)/2%Mod)%Mod; res=res*((1+(M/i))*(M/i)/2%Mod)%Mod; res=res*f[i]%Mod; ans=(ans+res)%Mod; } ans=(ans%Mod+Mod)%Mod; cout<<ans<<endl; return 0; }
来自:http://maijing3007.blog.163.com/blog/static/246120003201545101527359