For k∈N∗ there exists nk∈N∗ such that 2nk<10k<2nk+1 (nk+1 is the smallest element of the set {m∈N∗∣10k<2m}). As 2nk<10k<2nk+1, we get 10k<2nk+1<2⋅10k, so p(2nk+1)=1.
Multiplying by 5nk+1, we have 10k⋅5nk+1<10nk+1<2⋅10k⋅5nk+1. Dividing the first inequality by 10k and the second by 2⋅10k, we get 5⋅10nk−k<5nk+1<10nk−k+1, so p(5nk+1)≥5>p(2nk+1).
From 2nk<10k<2nk+1, by dividing the second inequality by 2, we conclude 5⋅10k−1<2nk<10k, so p(2nk)≥5. Multiplying the first inequality by 5nk, we obtain 10k−1⋅5nk+1<10nk<10k⋅5nk, so by dividing the first one by 5⋅10k−1 and the second by 10k, we obtain 10nk−k<5nk<2⋅10nk−k, that is p(5nk)=1<p(2nk).
The set {nk∣k∈N∗} has an infinity of elements because nk>k. As {nk∣k∈N∗}⊂A and {nk+1∣k∈N∗}⊂B, the sets A and B also have infinitely many elements.