2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) P- Fear Factoring

传送门:点击打开链接

2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) P- Fear Factoring_第1张图片


分析:        2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) P- Fear Factoring_第2张图片

题目比较有意思,这么转换就比较好求解了~


代码如下:

#include 
#include 
#include 
using namespace std;

typedef unsigned long long LL;
LL a,b;

LL func(LL n){
    if ( n == 0) return 0;
    LL ans = 0;
    LL t = 0;
    for (LL i=1; i<=n; i=t+1) {
         t = n/(n/i);
         ans += (i+t)*(t+1-i)/2*(n/i);
    }
    return ans;
}

int main(){
    while (scanf("%lld%lld",&a,&b)==2) {
        printf("%lld\n",func(b)-func(a-1));
    }
    return 0;
}

你可能感兴趣的:(基础数论)