Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Mathematically beautiful numbers problem solution

YASH PAL, 31 July 2024
In this HackerEarth Mathematically beautiful numbers problem solution While playing a mental math game, you realize that the number k is mathematically beautiful.
You then realize that the number x can be mathematically beautiful if it is represented as a sum of a sequence where each element is a power of k and all the numbers in the sequence are different. Your task is to determine whether the number is mathematically beautiful.
hackerEarth Mathematically beautiful numbers problem solution

HackerEarth Mathematically beautiful numbers problem solution.

#include<iostream>
using namespace std;
int m[40], t;
int main (){
cin >> t;
while(t--){
for(int i = 0; i < 40; i++)
m[i] = 0;
long long int x;
int k, cnt = 0;
cin >> x >> k;
while(x){
cnt++;
m[x % k]++;
x /= k;
}
if(m[0] + m[1] == cnt)
cout << "YESn";
else
cout << "NOn";
}
}

second solution

t = int(input())
while t > 0:
t -= 1
x, k = map(int, input().split())
good = True
while x > 0:
good &= x % k < 2
x //= k
print("YES" if good else "NO")
coding problems

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes