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 Base numbers problem solution

YASH PAL, 31 July 2024
In this HackerEarth Base numbers problem solution you are given three integers a, b, and n. Your task is to determine the number of positive integers x related to [1,10^9] such that ax^x is an n-digit number of base b.
HackerEarth Base numbers problem solution

HackerEarth Base numbers problem solution.

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
os<<ptt.first<<","<<ptt.second;
return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
os<<"{";
for(int i=0;i<vt.size();i++){
os<<vt[i]<<" ";
}
os<<"}";
return os;
}

ll a,n,b;
inline double log(ll a,ll b){
return log10(a)/log10(b);
}

inline bool ok(ll x,ll n){
long double v=floor(x*log(x,b)+log(a,b))+1;
if(v>=n){
return true;
}else{
return false;
}
}

void solve(){
ll l=0,r=1e9;
while(l<=r){
ll m=(l+r)/2;
if(ok(m,n)){
r=m-1;
}else{
l=m+1;
}
}
ll l2=0,r2=1e9;
while(l2<=r2){
ll m=(l2+r2)/2;
if(ok(m,n+1)){
r2=m-1;
}else{
l2=m+1;
}
}

cout<<l2-l<<endl;
}

int main(int argc,char* argv[]){
while(cin>>a>>n>>b){
solve();
}
return 0;
}
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