Skip to content

Commit

Permalink
added more prgs
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek27 committed Aug 18, 2014
1 parent 8b7b907 commit 64aba25
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions SuperTables-Interesting Binary Search Prob.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<iostream>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long

//SuperTables on HackerEarth based on Binary Search.
int main(){
ll t,n,a,b,L,R,M;
ll ans;
cin>>t;
while(t--){
cin>>a>>b>>n;
L=1;
R=max(a,b)*n;
while(L<=R){
ll mid = L + (R-L)/2;
//No of factors till mid

ll factors = mid/a + mid/b - mid*__gcd(a,b)/(a*b);
if(n==factors)
{
ans = max( (mid/a)*a,(mid/b)*b);
printf("%lld\n",ans);
break;
}
else if(factors>n){
L = mid;
}
else
R = mid;

}
}

return 0;
}

0 comments on commit 64aba25

Please sign in to comment.