[제 CUP 라운드] 형의 팀 (- 블록 합산 수론) 코드를 합산
- 아이디어 :
- 수식의 제곱의 합 : \. (1 + 2 ^ 2 ^ 2 ^ N-2 + ... + = \ {... N-FRAC에 * (N- + 1) * (2 * N- + 1)) (6)} {} \) , 접두어 및 치료
- 블록 합계 생각 :
- \ (\ lfloor \ FRAC {N } {I} \ rfloor \) 각각의 값에 대해있을 수있는 다수 \ (나는 \) 에게 해당 \ (I는 \) 축적 된 제품이 동일한에서 직접 사용되면, 포인트 대신 추가의
int res=0;
for(int l=1,r;l<=n;l=r+1){
r=n/(n/l);
res+=(n/i*(r-l+1));// n/i为块内每个数的值,同一个块都是相同的数值,(j-i+1)为块长
}
return res;
AcCode :
#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL n,m;
const LL mod=1e9+7;
LL qpow(LL a,LL b){
LL ans=1;
a%=mod;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
LL inv(LL a){
return qpow(a,mod-2);
}
LL getans(LL n){
return n*(n+1)%mod*(2*n+1)%mod*(inv(6))%mod;
}
LL cal(LL n){
LL ans=(1+n)*n%mod*n%mod*inv(2)%mod;
// bug(ans);
LL b=0;
for(LL i=1,j;i<=n;i=j+1){
j=n/(n/i);
b=b+(n/i)%mod*(getans(j)-getans(i-1))%mod;b%=mod;\
//bug(b);
}
//bug(b);
return (ans-b+mod)%mod;
}
int main(){
//bug(qpow(2,10));
// bug(getans(4)-getans(2));
scanf("%lld%lld",&n,&m);
cout<<cal(n)*cal(m)%mod<<endl;
return 0;
}