The problem is symmetric in x vs. 1/x so we can find the number of integers between 0 and 1000 that are either a power of two or 3 and just double the answer.
Note that any non-zero power of 2 is even and any non-zero power of 3 is odd so these two sets are disjoint.
There are 10 powers of 2, 0-9, and 6 non-zero powers of 3 that are less than 100.
We use non-zero power for 3 since we only want to count 1 = 20 = 30 once
That gets us 16 from 0 to 1000. Doubling this we get 32 but we don't want to count \(1 = \dfrac{1}{1}\)
twice so we subtract 1 from this getting 31 as you found.