Chapter 1: Q32E (page 50)
A positive integer is a power if it is of the form , where ,role="math" localid="1658399000008" are positive integers and .
(a) Give an efficient algorithm that takes as input a number and determines whether it is a square, that is, whether it can be written as for some positive integer . What is the running time of your algorithm?
(b) Show that if (with role="math" localid="1658399171717" , , and all positive integers), then either role="math" localid="1658399158890" .
(c) Give an efficient algorithm for determining whether a positive integer is a power. Analyze its running time.
Short Answer
- It is having iterations and the total running time of the algorithm is .
- then, the value of must equal to .
- The running time complexity of the given algorithm is .