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 Supertables problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Supertables problem solution, Little Timmy is exceptionally good at math tables, so his maths teacher decided to make things a bit more interesting.
 
His teacher takes two numbers A and B and merges the tables of A and B in sorted order (ascending order), removing the duplicates and thus creates supertable of A and B and asks Little Timmy the Nth number in the supertable.
 
Given A, B and N, calculate the Nth number in the supertable of A and B.
 
 
HackerEarth Supertables problem solution

 

 

HackerEarth Supertables problem solution.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
long long t,a,b,n;
cin >> t;
while ( t-- ) {
cin >> a >> b >> n;
long long p = __gcd(a,b);
p = (a*b)/p;
long long L,R,M;
L = 1;
R = 100000000000000000LL;
long long ans;
while ( L <= R ) {
M = (L+R)/2;
long long val = M/a + M/b - M/p;
if ( val == n ) {
ans = max((M/a)*a, (M/b)*b);
cout << ans << endl;
break;
}
else if ( val < n ) {
L = M+1;
}
else {
R = M-1;
}
}
}
return 0;
}
 
 
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