closed formula
approximation algorithm
boundary check and refactorings