-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
prateek27
committed
Aug 18, 2014
1 parent
8b7b907
commit 64aba25
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |