BZOJ and more than 1257 of the number of problem solution

Face questions

This question is one of divisible template title block;

First, know that people should be aware of the block, n / i have up to several 2 * sqrt (n), and the remainder but what does it matter?

Note that, as long as the n / i and the value of n / (i + d) values, the n% i to n (i + d) is the value of arithmetical series%! Because the n / i = n / (i + 1) * (i + 1) = n / i * (i + 1) = n / i * i + n / i;

Therefore, when it is rounded down tolerance of n / i of the arithmetic series;

Thus the nature of the use and arithmetic block of the series summation formula This question can be cut off;

#include <bits/stdc++.h>
using namespace std;
long long n,k;
int main()
{
    cin>>n>>k;
    long long ans=n*k;
    for(register long long l=1,r;l<=n;l=r+1){
        if(k/l==0) r=n;
        else r=min(k/(k/l),n);        
        ans-=((r-l+1)*(k/l*l)+(r-l+1)*(r-l)/2*(k/l));
    }
    cout << years; 
}

 

Guess you like

Origin www.cnblogs.com/kamimxr/p/11442182.html