2020牛客国庆集训派对day1 E.Zeldain Garden

204 篇文章 1 订阅
108 篇文章 0 订阅

2020牛客国庆集训派对day1 E.Zeldain Garden

题目链接

题目描述

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

示例2

输入

12 12

输出

6

示例3

输入

555 666

输出

852

对每一个数的分组数,显然就是它的因子数,题目要求的也即区间内的因子数和,果断 OEIS,有这样一个公式:
a ( n ) = 2 ∗ ( ∑ i = 1 f l o o r ( s q r t ( n ) ) f l o o r ( n i ) ) − f l o o r ( n ) 2 a(n) = 2*(\sum_{i=1}^{floor(sqrt(n))} floor(\frac{n}{i})) - floor(\sqrt{n})^2 a(n)=2(i=1floor(sqrt(n))floor(in))floor(n )2
可以在 O ( n ) O(\sqrt{n}) O(n ) 内计算出答案,完美解决这道题,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll l,r;
    cin>>l>>r;
    l--;
    ll sum1=0,u1=floor(sqrt(l));
    for(ll i=1;i<=u1;i++){
        sum1+=floor(double(l)/double(i));
    }
    sum1=2*sum1-u1*u1;
    ll sum2=0,u2=floor(sqrt(r));
    for(ll i=1;i<=u2;i++){
        sum2+=floor(double(r)/double(i));
    }
    sum2=2*sum2-u2*u2;
    cout<<sum2-sum1;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺 崽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值