mdarikrayhan's blog

By mdarikrayhan, history, 4 years ago, In English

A recursive function that can check if a number num is power a anohter number base.

bool isPowerof(long long num, long long base)
{
    if (num <= 0)
        return false;
    if (num % base == 0)
        return isPowerof(num / base, base);
    if (num == 1)
        return true;
    return false;
}
  1. Limitation : num<= $$$2^{62}$$$ and 2<=base<= $$$2^{62}$$$
  2. Time complexity : O($$$log_{base}^{num}$$$).
  3. Sample submission : 169977243.

Full text and comments »

  • Vote: I like it
  • -16
  • Vote: I do not like it