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:20
Ihave been given the number of guns per 100, and the total firearm-related deaths per 100,000. i have to find the actual number of guns per country and actual number of gun-related deaths. if somebody could show me how to do 1 question, i can finish the rest, i am just confused. tia
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
As with any small island country, cuba has fewer natural resources than countries such as brazil. this affects their economy in that cuba a) exports only manufactured products. b) exports more products than it imports.. c) must import more products than it exports. d) has imposed trade barriers against the united states.
Answers: 3
question
Computers and Technology, 24.06.2019 01:00
What shows the web address of the page that is currently displayed in the workspace? status window toolbar location bar internet box
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
Me if you do then you get 10 points and brainliest
Answers: 1
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, 26.06.2019 02:10