you can get the problem statement from here.
nice little problem.
tree_num is the sum of distinct powers of 3 with natural exponent. we can solve this problem easily if we can realize that any natural number is sum of distinct powers of 2 with natural exponent.
one illustration that any natural number is the sum of distinct powers of 2 with natural exponent is the binary representation of natural numbers. as with natural numbers we can also represent the tree numbers in binary representation and the conversion’s also similar, instead of sum of powers of 2, it is sum of powers of 3.
PS: be careful with IO. i got tle for cin/cout with ios::sync_with_stdio(0);cin.tie(0);. so either use fast io or scanf, printf