小G的约数

题 意 : 题意:

小 G 定 义 了 两 个 函 数 F ( n ) 为 n 的 约 数 和 小G定义了两个函数F(n)为n的约数和 GF(n)n

G ( n ) = F ( 1 ) + F ( 2 ) + . . . + F ( n − 1 ) + F ( n ) , 求 G ( G ( n ) ) . G(n)=F(1)+F(2)+...+F(n-1)+F(n),求G(G(n)). G(n)=F(1)+F(2)+...+F(n1)+F(n),G(G(n)).

考 虑 分 块 , 我 们 只 需 要 考 虑 1... n 中 每 一 个 因 子 的 贡 献 即 可 考虑分块,我们只需要考虑1...\sqrt{n}中每一个因子的贡献即可 1...n

显 然 , 对 于 因 子 i , 它 在 1... n 中 的 个 数 为 n / i , 那 么 它 的 贡 献 为 n / i ∗ i 显然,对于因子i,它在1...\sqrt{n}中的个数为n/i,那么它的贡献为n/i*i ,i,1...n n/i,n/ii

对 于 大 于 n 的 因 子 , 对 ∑ k = n + 1 n / i k 求 和 即 可 对于大于\sqrt{n}的因子,对\sum\limits_{k=\sqrt{n}+1}^{n/i}{k}求和即可 n ,k=n +1n/ik

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
#include<cstring>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
typedef unsigned long long ull;
inline int read(){int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
const int maxn = 1e6+5;
int main()
{
    ll n; cin>>n;
    ll ans=0;
    for(ll i=1;i<=sqrt(n);i++)
    {
        ans+=(n/i)*i;
        if(n/i>sqrt(n))
        {
            ll q=n/i;
            ll p=sqrt(n)+1;
            ans+=(q-p+1)*(q+p)/2;
        }
    }
    n=ans,ans=0;
    for(ll i=1;i<=sqrt(n);i++)
    {
        ans+=(n/i)*i;
        if(n/i>sqrt(n))
        {
            ll q=n/i;
            ll p=sqrt(n)+1;
            ans+=(q-p+1)*(q+p)/2;
        }
    }
    printf("%lld\n",ans);
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值