题意:求∑∑((n mod i)*(m mod j))其中1<=i<=n,1<=j<=m,i≠j。然后mod 19940417
本题坑我太久啊,思路:
∑∑((n mod i) * (m mod j)) 1<=i<=n, 1<=j<=m, i≠j= ∑(n mod i) * ∑(m mod i) - ∑((n mod i) * (m mod i))= ∑(n-[n/i]*i) * ∑(m-[m/i]*i) - ∑(nm-([n/i]+[m/i])i+[n/i][m/i]*i*i)
[cpp]
view
plaincopy
-
#include
-
#include
-
-
using namespace std;
-
-
typedef long long LL;
-
-
const LL MOD = 19940417;
-
-
LL sum(LL n)
-
{
-
return n*(n+1)%MOD*(2*n+1)%MOD*3323403%MOD;
-
}
-
-
LL Solve(LL m, LL n)
-
{
-
LL ans=0,i,last;
-
for(i=1;i<=m;i=last+1)
-
{
-
last=min(m,n/(n/i));
-
ans += (n/i)*(i+last)%MOD*(last-i+1)%MOD*9970209%MOD;
-
ans %= MOD;
-
}
-
return ans;
-
}
-
-
int main()
-
{
-
LL n, m;
-
cin>>n>>m;
-
if(n
-
LL ans=(n*n-Solve(n,n))%MOD*((m*m-Solve(m,m))%MOD);
-
ans+=-m*m%MOD*n%MOD+Solve(m, n)*m%MOD+Solve(m, m)*n%MOD;
-
ans%=MOD;
-
for(LL i=1,last;i<=m;i=last+1)
-
{
-
last=min(m,min(n/(n/i),m/(m/i)));
-
ans += -(n/i)*(m/i)%MOD*((sum(last)-sum(i-1))%MOD)%MOD;
-
ans %= MOD;
-
}
-
cout<<(ans%MOD+MOD)%MOD<
-
return 0;
-
}