rec algorithm
rec algorithm
added the modulo