If you are given two number with its power and told you which number is big. How do you calculate it.
For, instance you would say binary exponentiation technique. But this is bit harder when the test case number is bigger. There is also an easy way to solve this problem.
Suppose you are given 2^18 and 6^12. Then, you just take logarithm in both numbers. Then it will become 18*log2 and 12*log6. Logarithm function will break this number and make it a little number. which can be compare easily. But for this you have to Double number type, or you will get an error message.
Problem: Problem - 987B - Codeforces
Code:
void solve(){
ll a,b;
cin>>a>>b;
double num1 = b*log(a);
double num2 = a*log(b);
if(num1==num2) cout<<'='<<endl;
else if(num1>num2) cout<<'>'<<endl;
else cout<<'<'<<endl;
}
Comments
Post a Comment