The answer is pn.
Let ai=p(1+p)i−1 for i≥0. By induction we obtain f(ai)≡if(1)(modpn) for all i≥0.
If p>2 or p=2 and n=1, then
ai≡aj(modpn)⇒(1+p)j−i≡1(modpn+1)⇒i≡j(modpn).
Since ai+aj+paiaj=ai+j for all i,j≥0, the function defined by f(ai)≡ic(modpn), (0≤i<pn), satisfies the condition of the question for any choice of c∈Zpn.
ai≡aj(mod2n)⇒3j−i≡1(mod2n+1)⇒i≡j(mod2n−1)
and Zpn={ai:0≤i<2n−1}∪{−ai−1:0≤i<2n−1}. We also have 2f(−1)≡f(−1)+f(−1)≡f((−1)+(−1)+2(−1)(−1))≡f(0)≡0(mod2n).
Since ai−aj+2aiaj=ai+j, ai+(−aj−1)+2ai(−aj−1)=−ai+j−1, and (−ai−1)+(−aj−1)+2(−ai−1)(−aj−1)=ai+j for all i,j≥0, the function defined by f(ai)≡ic(mod2n) and f(−ai−1)≡ic+d(mod2n), (0≤i<2n−1), satisfies the condition of the question for any choice of c∈2Z2n and d∈2n−1Z2n as f(a)+f(−1)≡f(−a−1)(mod2n) for all a∈Zpn.