Problem 107716 · easy · Phase 01 Prerequisites & Setup

Is It a Power of the Base?

functions · powers · loops

Write is_power_of(n, base) that returns True if n equals base raised to some non-negative integer power (base**0 == 1 counts), and False otherwise.

Examples

Input:  n = 81, base = 3
Output: True

Input:  n = 12, base = 2
Output: False

Input:  n = 1, base = 5
Output: True

Constraints

  • -10**18 <= n <= 10**18
  • 2 <= base <= 100

Goals

  • Use repeated division instead of floating-point logs
  • Treat 1 as base to the power 0
Starting Python…