Ceiling algorithm.