calculation and recursive algorithmus