How to check if a number x is power of a number y

Правка en6, от mdarikrayhan, 2022-08-28 16:39:33

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.
Теги number theory, biginteger, powers, recursion

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский mdarikrayhan 2022-08-28 16:39:33 118 Tiny change: ' 2<=base<=$2^{62}$\n' -> ' 2<=base<= $2^{62}$\n'
en5 Английский mdarikrayhan 2022-08-28 16:11:37 232 Tiny change: ' and in **2^{x+y}e**. Here i' -> ' and in **$2^{x+y}**. Here i'
en4 Английский mdarikrayhan 2022-08-28 14:50:45 66
en3 Английский mdarikrayhan 2022-08-28 13:43:31 762 Resolved the issue with function.
en2 Английский mdarikrayhan 2022-08-28 11:06:48 0 (published)
en1 Английский mdarikrayhan 2022-08-28 11:06:04 972 Initial revision (saved to drafts)