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

HackerEarth Mathematically beautiful numbers problem solution

YASH PAL, 31 July 202411 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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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