Http://blog.chinaunix.net/u1/59687/showart_475042.html
1. Problem
Both A and B are integers and a> 1, B> 1
Calculate the upper integer of limit a/B, that is, a/B.
When a/B is divisible, the return value is a/B.
If not divisible, the returned value is int (a/B) + 1.
ThisAlgorithmOne application: If you have a dynamic growth buffer, the growth step is B,
The size of a buffer application is a. At this time, you can use this algorithm to calculate a combination of the buffer.
It can accommodate a, and the excess is not larger than B.
2. Method
INT (a + B-1)/B)
3. Proof of Hunton
Use up to indicate the rounded up.
Because a> 1, B> 1, and A and B are integers, you can set a = Nb + m
Where N is a non-negative integer, M is 0 to the number of B-1, then
A/B = N + M/B
(A + B-1)/B = n + 1 + (m-1)/B;
When M is 0,
Up (a/B) = n,
INT (a + B-1)/B) = N + int (1-1/B) = N
When M is 1 to the number of B-1, 0 <= M-1 <= B-2
Up (a/B) = n + 1,
INT (a + B-1)/B) = n + 1 + int (M-1)/B) = n + 1
Therefore, integers A and B of A> 1 and B> 1 have:
Up (a/B) = int (a + B-1)/B)