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 06:00
What role do chromosomes play in inheritance?
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
1. which of the following statements are true about routers and routing on the internet. choose two answers. a. protocols ensure that a single path between two computers is established before sending packets over it. b. routers are hierarchical and the "root" router is responsible for communicating to sub-routers the best paths for them to route internet traffic. c. a packet traveling between two computers on the internet may be rerouted many times along the way or even lost or "dropped". d. routers act independently and route packets as they see fit.
Answers: 2
question
Computers and Technology, 23.06.2019 18:30
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
Answers: 2
question
Computers and Technology, 24.06.2019 18:30
These factors limit the ability to attach files to e-mail messages. location of sender recipient's ability to open file size of file type of operating system used
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, 22.07.2021 14:00
question
Advanced Placement (AP), 22.07.2021 14:00
question
Social Studies, 22.07.2021 14:00
question
Mathematics, 22.07.2021 14:00
question
English, 22.07.2021 14:00
question
Mathematics, 22.07.2021 14:00
question
Health, 22.07.2021 14:00
Questions on the website: 13722361