hunterthompson4740 hunterthompson4740
  • 23-08-2019
  • Mathematics
contestada

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

Respuesta :

sqdancefan
sqdancefan sqdancefan
  • 23-08-2019

Explanation:

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.

Answer Link

Otras preguntas

Which of the following are solutions to the equation below? Check all that apply.
Which is a true statement about 7and14
Immediately after throwing her new doll the floor and breaking it , what emotion does Helen feel
Why is sodium extracellular if diffusion wants to put intracellular?
Convert the decimal number 183 into an equivalent 32 bit binary number. show all your work.
What simplified ratio correctly compares 36 inches to 4 feet? Drag and drop the appropriate numbers into the boxes. Blank : Blank Here are the numbers that a
Which of the following sentences shows correct capitalization? A. Stanley said, “Doctor livingstone, I presume?” B. Stanley said, “Doctor Livingstone, I pre
Factor the expression. 36y2 – 84y – 147 asap
what is the answer to the problem of 4/5x - 2 + 1/10x =7
What is the answer for question 1?