Ask Question
26 October, 12:30

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

+5
Answers (1)
  1. 26 October, 13:25
    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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers