subject

Write two different programs to compute x^n mod m (x, n and m are integers≥0).
Note that you are not allowed to use “pow” function from library
(a). powmod1(x, n,m)
It computes x^n mod m by repeated multiplications, i. e. using iteration.

(b). powmod2(x, n, m)
It computes x^n mod m by using the following inductive definition
x^0 mod m= 1
x^n mod m=〖〖(x⋅x mod m)〗^(n/2) 〗^ mod m if n is even
x^n mod m=〖(x⋅x〗^(n-1) mod m) mod m if n is odd
Discuss which the above program is more efficient using big-O notation. If you are not sure about which one is more efficient, test your code on computer, using the following data. Present the timing result to support your conclusion.
For x=29, m = 773, use n = 100,000,000, 500,000,000 and 1,000,000,000

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:10
Which are not examples of chronic or persistent stress? moving
Answers: 1
question
Computers and Technology, 22.06.2019 12:40
The most complicated four letter word
Answers: 1
question
Computers and Technology, 22.06.2019 13:00
Which option should u select to ignore all tracked changes in a document
Answers: 1
question
Computers and Technology, 22.06.2019 16:30
The most common battery cable terminal is a that provides a large surface contact area with the ability to tighten the terminal onto the battery post using a nut and bolt.
Answers: 2
You know the right answer?
Write two different programs to compute x^n mod m (x, n and m are integers≥0).
Note that you...
Questions
Questions on the website: 13722361