Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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
Programming101
Programmingoneonone

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 solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes