hdu5608 几类经典的根号复杂度算法

I, as a ACMer, always take algorithm complexity into consideration when programming. Today, I introduce you some elegant algorithms of root Complex.
摘要由CSDN通过智能技术生成

I, as a ACMer, always take algorithm complexity into consideration when programming. Today, I introduce you some elegant algorithms of root Complex.

转载请注明Reproduced please specifydna049.com

1. s(n)=ni=1ni

Since The range of ni contains at most 2n . There may exist a algorithm of complexity O(n) .

LL getsum(LL n){ // The code is simple and easy to understand
    LL sum = 0;
    for(LL i=1,j;i<=n;i=j+1){ 
        j = n/(n/i);
        sum += (j-i+1)*(n/i);
    }
    return sum;
}

Actually, s(n) donate the number of positive integer point under graph xy=1 .

2. σk(n)=d|ndk

  1. σ0(n) donate the number of divisors.
  2. σ1(n) donate the sum of divisors.
LL mypow(LL x,LL n){
    LL r = 1;
    while(n){
        if(n&1) r=r*x;
        n>>=1;  x=x*x;
    }
    return r;
}
LL getr(LL n,LL k){
    LL r = 0,d;
    for(d=1;d*d<n;++d){
        if(n%d==0)  r += mypow(d,k) + mypow(n/d,k);
    }
    if(d*d == n) r+=mypow(d,k);
    return r;
}

The code above is primary and trival.

3. f(n)=ni=1σk(i)

f(n)=i=1nσk(n)=i=1
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值