We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a0fee4 commit 434a6fbCopy full SHA for 434a6fb
1 file changed
bit_manipulation/is_K_power_of_N.py
@@ -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
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