The answer is n=83+89−1=171.
In general, if Ana has to decide between periods from the set P:={p1>p2>⋯>pr} of pairwise distinct relatively prime positive integers for r≥3, the answer is p2+p3−1.
### Bound
Suppose for the sake of contradiction that Ana has a winning sequence of integers x1,…,xn with n≤p2+p3−2. We will generate contradictions by providing two primes p,q∈P and associated nonconstant functions fp,fq:Z→Z with periods p and q respectively such that fp(xi)=fq(xi) for all i.
Claim — There exists a prime r∈P such that for all primes p∈P∖{r}, the set of integers {x1,…,xn} forms a complete residue class modulo p (i.e. for all t, there exists i such that xi≡t(modp)).
Claim — Suppose for the sake of contradiction that such r didn't exist, and there were in fact two primes p,q∈P such that {x1,…,xn} did not form a complete residue class modulo either p or q. Concretely, consider t,s such that there is no i with xi≡t(modp) and no j with xj≡s(modq).
Construct the functions fp,fq:Z→Z as
fp(x)={01if x≡t(modp)if x≡t(modp)
and
fq(x)={01if x≡s(modq)if x≡s(modq).
We have fp(xi)=fq(xi)=0 for all i, which is the desired contradiction.
Let r be the prime from the above claim. Let p,q be the largest two primes in P∖{r}, so n≤p+q−2. Construct the graph Gpq with vertex set {x1,…,xn} and edge xi∼xj if p∣xi−xj or q∣xi−xj. The following claim allows us to construct a pair of bad functions fp,fq.
Claim — The graph Gpq is disconnected.
*Proof.* Let Gp be the graph on vertex set {x1,…,xn} with edge xi∼xj if p∣xi−xj. Note that Gp is a collection of p disjoint cliques, one for each residue class modulo p.
Prune the graph into Gp′, where each clique Kr is replaced by a path of edge-length r−1. Define Gq′ similarly, and let Gpq′ be the union of Gp′ and Gq′.
Note that Gpq and Gpq′ have the exact same connectivity properties. We have
∣E(Gpq′)∣≤∣E(Gp′)∣+∣E(Gq′)∣=(n−p)+(n−q)≤n−2,
so Gpq′ is disconnected, as desired. □
Suppose A⊔B={x1,…,xn} are sets of disjoint vertices in Gpq. Construct the functions fp,fq:Z→Z as
fp(x)={01if x≡a(modp) for some a∈Aif x≡b(modp) for some b∈B
and
fq(x)={01if x≡a(modq) for some a∈Aif x≡b(modq) for some b∈B.
These are well defined due to the fact that p,q∤a−b for a∈A and b∈B, and the fact that A⊔B forms a complete residue class modulo p. Again, we have fp(xi)=fq(xi) for all i, which is the desired contradiction.
## Construction
Let n=p2+p3−1. We claim that Ana has a winning strategy with the selection xi=p1(i−1). Indeed, suppose that Banana writes down the values y1,…,yn in order. We will show that Ana can always reconstruct p.
Claim — If y1=⋯=yn, then Ana can correctly guess p=p1.
*Proof.* Suppose for the sake of contradiction that p<p1. Then, since x1,…,xn forms a complete residue class modulo p, f must be a constant function, which is the desired contradiction. □
We can now assume that y1,…,yn are not all equal, which means p=p1. Suppose for the sake of contradiction that there are two primes q,r<p1 with associated nonconstant functions fp,fq:Z→Z with periods q and r respectively, such that fq(xi)=fr(xi)=yi for all i.
The following claim shows that y1,…,yn must all be equal, which is the desired contradiction.
Claim — Let G be the graph on vertex set {0,…,q+r−2} with edge i∼j if ∣i−j∣∈{q,r}. The graph G is connected.
*Proof.* Note that G has q+r−2 edges, so it suffices to show that it has no cycles. Suppose for the sake of contradiction it had a cycle c1,…,ck with k≥3 and indices taken mod k.
Suppose first that ci+1−ci=q. Then, ci+2−ci+1 cannot be −q (else ci=ci+2), it cannot be r (else ci+2>q+r−2), so ci+2−ci+1∈{q,−r}.
ci+1−ci=q⟹ci+2−ci+1∈{q,−r}
ci+1−cici+1−cici+1−ci=−q⟹ci+2−ci+1∈{−q,r}=r⟹ci+2−ci+1∈{−q,r}=−r⟹ci+2−ci+1∈{q,−r}.
Thus, either all consecutive differences of vertices in the cycle are in {q,−r}, or all in {−q,r}. Assume the first case, proof is similar for second case.
Let a be the number of consecutive differences that are q, and b be the number that are −r. We see that a+b=k and qa−rb=0. The second condition implies that a≥r and b≥q, so we have k≥q+r, which is the desired contradiction since G has only q+r−1 vertices. □