Skip to content

Commit 279fe65

Browse files
authored
Add new algorithm (is_K_power_of_N)
1 parent b0413e5 commit 279fe65

1 file changed

Lines changed: 0 additions & 26 deletions

File tree

bit_manipulation/is_K_power_of_N.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
The error message `Syntax Error @ 1:1. tokenizer error: '`' is not a valid character in this position\` indicates that the Python parser is encountering an invalid character right at the beginning of the file.
2-
3-
The character causing the issue is the backtick symbol (`` ` ``) which seems to have been included at the very start of the code block. This is not a valid character to start a Python statement.
4-
5-
Here is the corrected code. It is identical to the previous version, but without the leading backtick, making it syntactically correct.
6-
7-
```python
8-
"""
9-
Author : Your Name
10-
Date : August 1, 2025
11-
12-
Task:
13-
Given two positive integers, n and k, determine if k is a power of n.
14-
15-
Implementation notes: Use a loop to repeatedly divide k by n.
16-
For a number k to be a power of n, it must be possible to reduce k
17-
to 1 by repeatedly dividing by n without any remainder.
18-
For example, 8 is a power of 2 because:
19-
8 / 2 = 4
20-
4 / 2 = 2
21-
2 / 2 = 1
22-
The final result is 1.
23-
"""
24-
25-
261
def is_k_power_of_n(n: int, k: int) -> bool:
272
"""
283
Return True if k is a power of n or False otherwise.
@@ -75,4 +50,3 @@ def is_k_power_of_n(n: int, k: int) -> bool:
7550
import doctest
7651

7752
doctest.testmod()
78-
```

0 commit comments

Comments
 (0)