Solution:
For a nice number n and a given partition of the set {1,2,…,n} into two-element subsets such that the sum of the elements in each subset is a power of 3, we say that a,b∈{1,2,…,n} are paired if both of them belong to the same subset.
Let x be a nice number and k be a (unique) non-negative integer such that 3k≤x<3k+1. Suppose that x is paired with y<x. Then, x+y=3s, for some positive integer s. Since
3s=x+y<2x<2⋅3k+1<3k+2
we must have s<k+2. On the other hand, the inequality
x+y≥3k+1>3k
implies that s>k. From these we conclude that s must be equal to k+1, so x+y=3k+1. The last equation, combined with x>y, implies that x>23k+1.
Similarly as above, we can conclude that each number z from the closed interval [3k+1−x,x] is paired with 3k+1−z. Namely, for any such z, the larger of the numbers z and 3k+1−z is greater than 23k+1 which is greater than 3k, so the numbers z and 3k+1−z must necessarily be in the same subset. In other words, each number from the interval [3k+1−x,x] is paired with another number from this interval. Note that this implies that all numbers smaller than 3k+1−x are paired among themselves, so the number 3k+1−x−1 is either nice or equals zero. Also, the number 3k must be paired with 2⋅3k, so x≥2⋅3k.
Finally, we prove by induction that an=2n−1, where an is the number of nice positive integers smaller than 3n. For n=1, the claim is obviously true, because 2 is the only nice positive integer smaller than 3. Now, assume that an=2n−1 for some positive integer n. We will prove that an+1=2n+1−1. To prove this, first observe that the number of nice positive integers between 2⋅3n and 3n+1 is exactly an+1−an. Next, observe that 3n+1−1 is nice. For every nice number 2⋅3n≤x<3n+1−1, the number 3n+1−x−1 is also nice and is strictly smaller than 3n. Also, for every positive integer y<3n, obviously there is a unique number x such that 2⋅3n≤x<3n+1−1 and 3n+1−x−1=y. Thus,
an+1−an=an+1⇔an+1=2an+1=2(2n−1)+1=2n+1−1
completing the proof.
In summary, there are 22022−1 nice positive integers smaller than 32022.