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=1floor(sqrt(n))floor(ni))?floor(n)2a(n) = 2*(\sum_{i=1}^{floor(sqrt(n))} floor(\frac{n}{i})) - floor(\sqrt{n})^2a(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;
}