Zoj 3175 Number of Containers (nbut1375) calculates n/1 + n/2 + n/3 + n/4.

Source: Internet
Author: User

[1, 1375] Guess The Number
Time Limit: 1000 MS memory limit: 65535 K

Problem description
For two integers m and k, k is said to be a container of m if k is divisible by m. given 2 positive integers n and m (m <n), the function f (n, m) is defined to be the number of containers of m which are also no greater than n. for example, f (5, 1) = 4, f (8, 2) = 3, f (7, 3) = 1, f (5, 4) = 0...

 


Let us define another function F (n) by the following equation:

 

Now given a positive integer n, you are supposed to calculate the value of F (n ).

Input
There are multiple test cases. The first line of input contains an integer T (T <= 200) indicating the number of test cases. Then T test cases follow.

Each test case contains a positive integer n (0 <n <= 2000000000) in a single line.
Output
For each test case, output the result F (n) in a single line.
Sample Input
2
1
4
Sample output
0
4
Prompt
No source
ZOJ 3175 Number of Containers

 

 

Question:

Calculate n * (1/1 + 1/2 + 1/3 + ...... 1/(n-2) + 1/(n-1)-n
Value

Because n is very large, it cannot be directly violent.

 

 

The number of All Integer Points on the line is n/I.

So n/1 + n/2 + n/3 + ...... N/(n-2) + n/(n-1) + n/n can be expressed as I * (n/I) = n this line

The answer is the number of Integer Points in the area enclosed by the line and coordinate axis.

Draw a line x = y and x * y = n to know the area is symmetric with x = y.

Let's calculate n/1 + n/2 + n/3 + ...... Obtain k = sqrt (n) (1 trapezoid) and multiply it by 2 (the area of 2 trapezoid is duplicated) subtract k * k duplicate regions

 

[Cpp]
# Include <stdio. h>
# Include <math. h>

Int main ()
{
Int t;
Scanf ("% d", & t );
Int n;
While (t --)
{
Int I;
Int t;
Long sum = 0;
Scanf ("% d", & n );
T = (int) sqrt (double) n );
For (I = 1; I <= t; I ++)
Sum + = (n/I );
Sum * = 2;
Sum = sum-t * t-n;
Printf ("% lld \ n", sum );
}
Return 0;
}

# Include <stdio. h>
# Include <math. h>
 
Int main ()
{
Int t;
Scanf ("% d", & t );
Int n;
While (t --)
{
Int I;
Int t;
Long sum = 0;
Scanf ("% d", & n );
T = (int) sqrt (double) n );
For (I = 1; I <= t; I ++)
Sum + = (n/I );
Sum * = 2;
Sum = sum-t * t-n;
Printf ("% lld \ n", sum );
}
Return 0;
}
In addition, we can use this method to quickly obtain n/1 + n/2 + n/3 +... n/n

 

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.