title: Does the standard library of C# have an easy way to check whether a number is a power of another number?
body: <p>I'm trying to see if there is a good way to find whether, given <code>int</code>s <code>b</code> and <code>n</code>, there exists an int <code>a</code> such that <code>a^n=b</code>. In other words, something more efficient than the bad solution I wrote below </p>
  
  <pre><code>private static bool HasBase(int b, int n)
  {
      for(int a = 1; a &lt;= int.MaxValue; ++a)
      {
          int pow = Power(a, n);
          if(pow == b)
              return true;
          else if(pow &gt; b)
              return false;
      }
      return false;   
  }
  
  private static int Power(int a, int n) 
  {
      return Enumerable.Range(a, n).Aggregate(1, (prev, cur) =&gt; prev * cur);
  }
  </code></pre>