Category : logarithm

Question link My code bool isPowerOfThree(int n) { if(n == 0) return false; double x = log(n)/log(3); if(x == ceil(x)) return true; return false; } Why am I getting the wrong answer for n = 243? I cout the both x and ceil(x) and both are equal. Also when I do the log10 instead of ..

Read more

Original problem. Find the maximum value of Hamming distance M, in decimal, in range [a, b] so that a at least 1, b at most 10^1000000. Let num_a=log10(a)+1, num_b=log10(b)+1, I see that: If num_a!=num_b, so M=num_b, i.e., M(1, 11)=M(1, 10)=2, Else, I realize that, we should start from the their first left digits, if they ..

Read more

I am trying to calculate really accurate values more than 18 decimal places. I am trying to calculate log10 (1e18 +1) by a C++ program. The value of log10 (1e18 +1) is really accurate and I don’t know of logarithm function can hold ? https://www.wolframalpha.com/input/?i=log+base+10+of+1e18+%2B+1 Here it’s my code: #include <iostream> #include <iomanip> #include <cmath> ..

Read more