• + 1 comment

    Java (math):

        public static int utopianTree(int n) {
            int closestOdd = n % 2 == 0 ? n + 1: n;
            int i = ((closestOdd-1)/2) + 2;
            int res = (int)Math.pow(2, i) - 2;
            
            if(n%2 == 0) {
                res /= 2;
            }
            
            return res;
        }