You are not logged in. Please login at www.codechef.com to post your questions!

×

# a to the power b form

 0 How to check if a number n is of the form a^b. problem link https://www.codechef.com/problems/APOWB asked 06 Dec '17, 15:25 66●6 accept rate: 0%

 1 Simple idea is to precompute a set containing all powers >= 2nd power of all numbers from 2 to 1e5. This will solve problem for input values upto 1e10 because minimum value of b is 2. Now, for values of a > 1e5, we realize that 4th power of a will always be > 1e16, but in input, all N <= 1e16. So, we will alsot take square root and cube root, and check if sqrtsqrt == N || cbrtcbrt*cbrt == N || set.contains(N).. If any of above is true, answer is true. Hope u find this helpful.. answered 06 Dec '17, 15:53 3.1k●11●35 accept rate: 22%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×241

question asked: 06 Dec '17, 15:25

question was seen: 144 times

last updated: 06 Dec '17, 15:53