Advertisement
STANAANDREY

isPow

Sep 5th, 2019
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. inline bool isPow(int n)
  2. {
  3.     for (int base = 2; base * base <= n; base++)
  4.     {
  5.         int b1 = 0, p = 1;
  6.         for (int b = 1; b <= n; b++)
  7.         {
  8.             while (b1 <= b)
  9.             {
  10.                 p *= base;
  11.                 b1++;
  12.             }
  13.             if (n == p)
  14.                 return true;
  15.         }
  16.     }
  17.     return false;
  18. }
  19. inline bool isPowOfBase(int power,int base)
  20. {
  21.     if (power == 1)
  22.         return true;
  23.     if (base == 1)
  24.         return power == 1;
  25.     if (!base)
  26.         return !power;
  27.  
  28.     int temp = base;
  29.     while(temp < power) temp *= base;
  30.     return temp == power;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement