This function is not reversing the tree, it swapping the left and
right sub trees. for ex.
6
5 8
4 7 9
1 11
2
=
6
8 5
9 4
111
@Sammm Yes you are correct. I wrote 2 by mistake.
it should be i. because (log n)/log i = log n to the base i. So if i^m
= n
=log n to the base i = integer.
@Lucifer I think that your approach is the best optimized. My algo is
testing all the numbers while yours uses only prime factors of N.
On
This algorithm won't work as primes might have different power. for
eg. N=12
12 is divisible by 2 so it ends up being 3. then 3 divides by 3. So it
prints possible. But the actual answer is no.
Correct code:
for (int i=2;i=sqrt(n);i++)
{
float ans = log(n)/log(2);
int an = ans;
if