implement finabocci in O(n) complexity