Mathematically beautiful numbers  Hackerearth practice problem solution
Problem:
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.
Task
Your task is to determine whether the number is mathematically beautiful.
Input format
 The first line contains T denoting the number of test cases.
 The next T lines contain
Output Format
For each test case, output “YES” if
$x$is “mathematically beautiful” and “NO” otherwise.
Constraints
$T<=1000$
$(1<=x<={10}^{18})$
$(2<=k<=9)$
$91={3}^{0}+{3}^{2}+{3}^{4}$
Code:
Here I am going to give you two solution first one is on the basis of C language and second one is on the basis of c++ language which you can submit in c++14 and c++17 also
Solution 1 ( C language):
Solution 2 ( C++ language):
Recommended Post:

Hackerearth Problems:
 Very Cool numbers  Hacker earth solution
 Birthday party  Hacker earth solution
 Most frequent  hacker earth problem solution
 program to find symetric difference of two sets
 cost of balloons  Hacker earth problem solution
 Chacha o chacha  hacker earth problem solution
 jadu and dna  hacker earth solution
 Bricks game  hacker earth problem
 AntiPalindrome strings  hacker earth solution
 connected components in the graph  hacker earth data structure
 odd one out  hacker earth problem solution
 Minimum addition  Hackerearth Practice problem
 The magical mountain  Hackerearth Practice problem
 The first overtake  Hackerearth Practice problem
Data structure:
 Program to find cycle in the graph
 Implementation of singly link list
 Implementation of queue by using link list
 Algorithm of quick sort
 stack by using link list
 program to find preorder post order and inorder of the binary search tree
 Minimum weight of spanning tree
 Preorder, inorder and post order traversal of the tree
Key points:
Bahut sahi rajnish ise tarah lage raho ek din top wbsite me hoge ye
useful