# [CUP first round] brother's team summed code (number theory - block summation)

[CUP first round] brother's team summed code (number theory - block summation)

Title chain (meter garlic off)

  • Ideas:
  • Sum of squares of the formula: \ (. 1 + 2 ^ 2 ^ 2 ^ n-2 + ... + = \ {n-FRAC * (n-+. 1) * (2 * n-+. 1)). 6} {} \) , the prefix and treatment
  • Block sum thinking:
    • \ (\ lfloor \ frac {n } {i} \ rfloor \) For each value, there may be multiple \ (I \) correspond to those \ (I \) points a, when the accumulated product used directly in the same Instead of addition
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;
}

Guess you like

Origin www.cnblogs.com/sstealer/p/11372352.html