Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Mathematically beautiful numbers problem solution

YASH PAL, 31 July 202413 February 2026
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 solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes