2020牛客国庆集训派对day1 E.Zeldain Garden(数论)

题目链接:https://ac.nowcoder.com/acm/contest/7817/E

题目描述
Boris is the chief executive officer of Rock Anywhere Transport (RAT) company which specializes in supporting music industry. In particular, they provide discount transport for many popular rock bands. This time Boris has to move a large collection of quality Mexican concert loudspeakers from the port on the North Sea to the far inland capital. As the collection is expected to be big, Boris has to organize a number of lorries to assure smooth transport. The multitude of lorries carrying the cargo through the country is called a convoy.
Boris wants to transport the whole collection in one go by a single convoy and without leaving even a single loudspeaker behind. Strict E.U. regulations demand that in the case of large transport of audio technology, all lorries in the convoy must carry exactly the same number of pieces of the equipment.
To meet all the regulations, Boris would like to do some planning in advance, despite the fact that he does not yet know the exact number of loudspeakers, which has a very significant influence on the choices of the number and the size of the lorries in the convoy. To examine various scenarios, for each possible collection size, Boris calculates the so-called “variability”, which is the number of different convoys that may be created for that collection size without violating the regulations. Two convoys are different if they consist of a different number of lorries.
For instance, the variability of the collection of 6 loudspeakers is 4, because they may be evenly divided into 1, 2, 3, or 6 lorries.

输入描述:
The input contains one text line with two integers N, M (1 ≤ N ≤ M ≤ 10^12 ), the minimum and the maximum number of loudspeakers in the collection.

输出描述:
Print a single integer, the sum of variabilities of all possible collection sizes between N and M,inclusive.

示例1

输入

2 5

输出

9

分析

数论中有个很牛的结论:
n之内的所有因数个数的计算方法为:n / 1 + n / 2 + n / 3 … n / n ;

还有个问题, n 可以到 10^12 ,不能直接线性。
那么例如当我们枚举 n = 12 时,发现 12 / (7, 8, 9, 10, 11, 12) 都为 1 ,我们可以只计算一次把他们全部计算出来;
或者发现,y = n / x 这个函数关于 y = x 对称,对称为点(√n,√n),因此由函数图像面积对称可以知道,只需求出前 √n 数据范围内的面积 ans , ans * 2 - √n * √n 即为答案。

代码
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL X(LL n)
{
    LL l, r;
    LL ans = 0;
    for( l = 1; l <= n; l = r+1)
    {
        r = n/(n/l);
        ans += n/l *(r - l + 1);
    }
    return ans;
    /*
    for(l=1; l<=t; l++)
            ans += n/l;
    ans = ans*2-t*t;
    return ans;
    */
}
int main(){
    int t;
        LL x,y;
        cin>> x>>y;
        printf("%lld\n",X(y)-X(x-1));
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值