codevs2606 Approximate and problem

Source: Internet
Author: User

Title Description Description

Smart has recently been addicted to the study of approximations.

For a number x, the function f (x) represents the and of all the approximations of X. For example: F (6) =1+2+3+6=12. For a x,smart you can quickly figure out F (X). The problem now is that, given two positive integers, x, y (x<y), Smart wants to figure out the value of f (X) +f (x+1) +......+f (Y) as soon as possible, can you help smart figure out the value?

Enter a description input Description

The input file is only one line, two positive integers X and y (x<y), indicating that f (X) +f (x+1) +......+f (Y) needs to be computed.

outputs description output Description

The output is only one row and is the value of f (X) +f (x+1) +......+f (Y) .

sample input to sample

2 4

Sample output Sample outputs

14

data size & Hint

There is 1≤x

There is 1≤x

There is 1≤x

Positive solutions: chunking

Problem Solving Report:

  is said to be a universal group problem, I actually thought for so long, no.

The sum of the approximate sum of the interval [l,r], and the direct to the endpoint subtraction.  Then consider the answer must be ans=∑[n/i]*i (1<=i<=n); But we don't have to. For once all I, can be [n/i] equal interval processing (block processing), directly to this interval sum is OK.

1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - using namespacestd; -typedefLong LongLL; the //ans=∑[n/i]*i (1<=i<=n); by [n/i] chunking -  -InlineintGetint () - { +        intw=0, q=0;CharC=GetChar (); -         while((c<'0'|| C>'9') && c!='-') C=getchar ();if(c=='-') q=1, c=GetChar (); +         while(c>='0'&& c<='9') w=w*Ten+c-'0', C=getchar ();returnQ? -w:w; A } at  - inline ll solve (ll N) { -     if(n==0|| n==1)returnN; -LL left=1, right; LL ans=0; -      while(left<=N) { -right=n/(N/left);//determine the right endpoint for the same value [n/i] inans+= (n/left) * (left+right) * (right-left+1)/2; -left=right+1; to     } +     returnans; - } the  *InlinevoidWork () { $LL x, y; X=getint (); y=getint ();Panax Notoginsengprintf"%lld", Solve (y)-solve (X-1)); - } the  + intMain () A { the Work (); +   return 0; -}

codevs2606 Approximate and problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.