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

How can the congressional power to investigate provide for checks and balances among the branches of government? A. The power to investigate can result in subs
A wall can be built by 6 men working 8 hours per day in 5 days. how many days will it take 4 men to build the wall if they work only 5 hours per day?
Which expression can be used to convert 80 US dollars (USD) to Australian dollars (AUD)? 1 USD = 1.0343 AUD 1 AUD = 0.9668 USD A. 80 USD x 0.9668 USD/1 AUD B. 8
how many significant digits are in the number 101.0100?
How do you determine what could represent a function in algebra
what is the lowest term of 8/12?
Islam spread through the
You have a friendship club. there are 12 members in your club. The 12th day of each month, you have a friendship call. Each member of the club talks to every ot
Which is the least serve form of heat illness
What is (-7)^5 in expanded form?