Fun with Integers CodeForces - 1062D

http://codeforces.com/contest/1062/problem/D

 

考虑每个乘数x的贡献

x=2时 (+-2,+-4) (+-3,+-6) (+-4,+-8)...

x=3时 (+-2,+-6) (+-3,+-9) (+-4,+-12)...

......

规律就很显然了

 

#include 
using namespace std;
typedef long long ll;
const int maxn=1e5+10;

int main()
{
    ll ans,n,i;
    scanf("%lld",&n);
    ans=0;
    for(i=2;i<=n;i++){
        ans+=(4ll*(n/i-1))*i;
    }
    printf("%lld\n",ans);
    return 0;
}

 

你可能感兴趣的:(思维)