We prove that the answer is yes; for every
S⊂{1,2,…,2017} there exists a suitable n.
Specially, n can be a power of 2: n=2w1 with some
nonnegative integer w1. Write ak(n)=2wk; then
2wk+1=ak+1(n)=P(ak(n))=P(2wk)=1⋅2⋅4⋯2wk=22wk(wk+1),
so
wk+1=2wk(wk+1).
The proof will be completed if we prove that for each choice of S
there exists an initial value w1 such that wk is even if and
only if k∈S.
Lemma. Suppose that the sequences (b1,b2,…) and
(c1,c2,…) satisfy
bk+1=2bk(bk+1) and
ck+1=2ck(ck+1) for k≥1, and
c1=b1+2m. Then for each k=1,…m we have
ck≡bk+2m−k+1(mod2m−k+2).
As an immediate corollary, we have bk≡ck(mod2) for
1≤k≤m and bm+1≡cm+1+1(mod2).
Proof. We prove the by induction.
For k=1 we have c1=b1+2m so the statement holds.
Suppose the statement is true for some k<m, then for k+1 we
have
ck+1=2ck(ck+1)≡2(bk+2m−k+1)(bk+2m−k+1+1)=2bk2+2m−k+2bk+22m−2k+2+bk+2m−k+1==2bk(bk+1)+2m−k+2m−k+1bk+22m−2k+1≡2bk(bk+1)+2m−k(mod2m−k+1),
therefore
ck+1≡bk+1+2m−(k+1)+1(mod2m−(k+1)+2).
Going back to the solution of the problem, for every
1≤m≤2017 we construct inductively a sequence
(v1,v2,…) such that
vk+1=2vk(vk+1), and for every
1≤k≤m, vk is even if and only if k∈S.
For m=1 we can choose v1=0 if 1∈S or v1=1 if
1∈/S. If we already have such a sequence
(v1,v2,…) for a positive integer m, we can choose
either the same sequence or choose v1′=v1+2m and apply the
same recurrence vk+1′=2vk′(vk′+1). By the
Lemma, we have vk≡vk′(mod2) for k≤m, but
vm+1 and vm+1′ have opposite parities; hence, either the
sequence (vk) or the sequence (vk′) satisfies the condition
for m+1.
Repeating this process for m=1,2,…,2017, we obtain a
suitable sequence (wk).