
Problem
Solution
Submissions
Number is a Power of Another Number
Certification: Intermediate Level
Accuracy: 0%
Submissions: 0
Points: 10
Write a C# program to determine if a given number x is a power of another number y. In other words, check if there exists an integer n such that y^n = x.
Example 1
- Input: x = 1024, y = 2
- Output: true
- Explanation:
- 2^10 = 1024, so 1024 is a power of 2.
Example 2
- Input: x = 100, y = 10
- Output: true
- Explanation:
- 10^2 = 100, so 100 is a power of 10.
Constraints
- 1 ≤ x ≤ 2^31 - 1
- 1 ≤ y ≤ 2^31 - 1
- Time Complexity: O(log x)
- Space Complexity: O(1)
Editorial
My Submissions
All Solutions
| Lang | Status | Date | Code |
|---|---|---|---|
| You do not have any submissions for this problem. | |||
| User | Lang | Status | Date | Code |
|---|---|---|---|---|
| No submissions found. | ||||
Solution Hints
- Use the property of logarithms to solve this problem.
- Consider edge cases like x = 1 or y = 1.
- Be careful about floating-point precision when using logarithms.
- You can also use repeated division to check if y divides x perfectly until x becomes 1.