Perfect Power
A Power Number is defined as a number greater than zero that can be expressed as X^Y, where X and Y are integers greater than one. Thus, the first few (in order) are:
This function takes an integer i and returns the (zero-indexed) ith power number. Some examples:
Approach 1: Brute Force
Complexity: O(nlogn) time. The priority queue has to manage at least one more element than it takes out, so its size increases linearly, and so each subsequent operation will take log(k+1) more work, where k begins at 0 and increases by one n amount of times where n is the total number of elements in the matrix. O(n/2) space
Approach 2: Heap Generators
Last updated