Ask Question
7 January, 00:32

Using pseudo-code, describe a recursive algorithm to find n! mod m, when m, n? Z+.

+3
Answers (1)
  1. 7 January, 00:47
    0
    A recursive algorithm has a terminating condition and a recursive rule.

    The function "facMod" will terminate with an output of 0 if m ≤ n, because m would be a factor of n!. It will terminate with an output of 1 if n < 2.

    Otherwise, it is the product mod m of n and the "facMod" of n-1.

    facMod (m, n) : = If (m ≤ n, 0, If (n < 2, 1, Mod (n*facMod (m, n-1), m)))

    __

    In this code, the If (a, b, c) statement returns b for a=true, otherwise it returns c. The Mod (a, b) statement returns a modulo b.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Using pseudo-code, describe a recursive algorithm to find n! mod m, when m, n? Z+. ...” in 📗 Mathematics if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers