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 <bits/stdc++.h>
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;
}

猜你喜欢

转载自blog.csdn.net/sunyutian1998/article/details/84094021