title: Check if one integer is an integer power of another
body: <p>This is an <a href="http://www.glassdoor.com/Interview/Given-2-numbers-x-and-y-check-if-x-is-an-integer-power-of-y-For-instance-x-8-y-2-would-return-true-and-x-10-and-y-QTN_111532.htm" rel="noreferrer">interview question</a>: "Given 2 integers x and y, check if x is an integer power of y" (e.g. for x = 8 and y = 2 the answer is "true", and for x = 10 and y = 2 "false").   </p>
  
  <p>The obvious solution is:<pre><code>int n = y; while(n &lt; x) n *= y; return n == x</code></pre></p>
  
  <p>Now I am thinking about how to improve it.</p>
  
  <p>Of course, I can check some special cases: e.g. both <code>x</code> and <code>y</code> should be either odd or even numbers, i.e. we can check the least significant bit of <code>x</code> and <code>y</code>. However I wonder if I can improve the core algorithm itself.</p>