We present new theoretical algorithms that sums the n-ary comparators output in order to get the permutation indices in order to sort a sequence. By analysing the parallel ranking algorithm, we found that the special comparators number of elements it processes divide the number of elements to be sorted. Using the divide and conquer method, we can express the sorting problem into summing output of comparators taking a prime number of elements, given that this prime number divides the initial disordered sequence length. The number of sums is directly related to the Maundy cake problem. Furthermore, we provide a new sequence that counts the number of comparators used in the algorithms.