Zoj 3175 number of containers

Source: Internet
Author: User
/*
* Zoj3175.c
*
* Created on: 2011-9-20
* Author: bjfuwangzhu
*/
/*
Question Description: given an N, evaluate 1, 2... N the approximate number of all numbers and F (N)
For example, F (5) = 10-5, F (4) = 8-4
Because N is very large, there are two ways to think about it. The first is to find the recursion or formula of the function. It seems very difficult and every clue
Another way of thinking is to calculate by segment, that is, the number of statistical intervals containing this approximate number, which can be calculated by O (1) time.
The next step is how to split this section. In fact, this problem is reflected in the coordinate system. For x * Y <= N, we need to find all the positive integer points in this graph.
We use a straight line x = y to divide this image into two parts. Obviously, these two parts are symmetric, so we can make I = [1, SQRT (n)] accumulate N/I (actually the section I mentioned earlier)
This is another * 2, but we noticed that we calculated the elements on the diagonal line twice, so we need to subtract K * K (k = SQRT (n ))
Why is this? We regard the whole point as the base point, that is, the area is obtained through the number base point. We correspond to the hyperbolic coordinate, and find that the overlapping part of Each recalculation is exactly a square.
Is K * k
*/

# Include <stdio. h>
# Include <math. h>
Typedef long ll;
Int main (){
# Ifndef online_judge
Freopen ("data. In", "r", stdin );
# Endif
Int T, I, Te, N;
Ll res;
While (~ Scanf ("% d", & T )){
While (t --){
Scanf ("% d", & N );
Te = (INT) SQRT (N * 1.0 );
For (I = 1, Res = 0; I <= tE; I ++ ){
Res + = N/I;
}
Res = (RES <1)-te * te;
Res-= N;
Printf ("% LLD \ n", Res );
}
}
Return 0;
}

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.