Skip to content

Commit 434a6fb

Browse files
authored
Add new algorithm (is_K_power_of_N)
1 parent 7a0fee4 commit 434a6fb

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This program checks if k is a power of n.
2+
3+
def is_k_power_of_n(n, k):
4+
"""
5+
Checks if k can be reduced to 1 by repeatedly dividing it by n.
6+
"""
7+
if n == 1:
8+
return k == 1
9+
if n <= 0 or k <= 0:
10+
return False
11+
while k % n == 0:
12+
k //= n
13+
return k == 1
14+
15+
n = int(input("Enter the base (n): "))
16+
k = int(input("Enter the number to check (k): "))
17+
print(is_k_power_of_n(n, k))

0 commit comments

Comments
 (0)