bzoj2956 -- 数论分块
直接分块就行了。注意要求出2和6的逆元。
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 #define M 19940417 7 inline int _Min(int x,int y){return x<y?x:y;} 8 long long i,j,Sum,Ans,n,m; 9 int main() 10 { 11 scanf("%lld%lld",&n,&m); 12 if(n>m)swap(n,m); 13 for(i=j=1;i<=m;i=j+1){ 14 j=_Min(m/(m/i),m); 15 Sum=(Sum-(m/j)*(j+i)%M*(j-i+1)%M*9970209%M)%M; 16 } 17 Sum=(Sum+m*m%M)%M;Ans=n*n%M*Sum%M; 18 for(i=j=1;i<=n;i=j+1){ 19 j=_Min(n/(n/i),n); 20 Ans=(Ans-(n/j)*(j+i)%M*(j-i+1)%M*9970209%M*Sum%M)%M; 21 } 22 Ans=(Ans-n*m%M*n%M)%M; 23 for(i=j=1;i<=n;i=j+1){ 24 j=_Min(n,_Min(n/(n/i),m/(m/i))); 25 Ans=(Ans+(m/i)*n%M*(i+j)%M*(j-i+1)%M*9970209%M+(n/i)*m%M*(i+j)%M*(j-i+1)%M*9970209%M+(n/i)*(m/i)%M*(i%M*(i-1)%M*((i<<1)-1)%M-j%M*(j+1)%M*((j<<1)+1)%M)%M*3323403%M)%M; 26 } 27 printf("%lld",(Ans+M)%M); 28 return 0; 29 }