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, 23.06.2019 00:30
Quick pl which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
Which software would you use to create a print design? a. illustrator b. audacity c. reaper d. dreamweaver
Answers: 2
question
Computers and Technology, 23.06.2019 20:30
If chris has a car liability insurance, what damage would he be covered for
Answers: 1
question
Computers and Technology, 24.06.2019 06:30
Adrawing that places all lines parallel to the z axis at an angle from the horizon is 99 ! a. an oblique drawing b. a perspective drawing c. an auxiliary view d. a one-point perspective drawing
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
question
Mathematics, 24.01.2020 00:31
question
Chemistry, 24.01.2020 00:31
question
World Languages, 24.01.2020 00:31
Questions on the website: 13722367