标签:xtend nta you tin tor void instant col call
Provide an implementation of the following interface: public interface Powers extends Iterator<Long> { /* Returns the next integer a in the arithmetic sequence of integers where * a = m^n, m > 1 n > 1, and m and n are both integers * Thus, the first few outputs will be 4, 8, 9, 16, 25, 27, 32, 36, etc. */ public Long next(); /* Resets the sequence to the beginning, such that the next call to next() * will return 4. */ public void reset(); }
1) Use a minheap 2) Upon reset (or instantiation), make sure heap is cleared with 4 on the top with {2,2} for m^n as metadata. 3) When next is called, pop the min and add 8 {2,3} and 9 {3,2} 4) Repeat for {m,n+1} when you pop {m,n}. If a {m,2} is popped, then add {m+1,2} 5) For any existing values, push {m,n+2} instead 6) Rinse and repeat for each next().
the arithmetic sequence of integers
标签:xtend nta you tin tor void instant col call
原文地址:http://www.cnblogs.com/apanda009/p/8016120.html