Solution 1
First, let's split it into two cases to get rid of the absolute value sign
∣∑k=1nlog10f(k)∣=1⟺∑k=1nlog10f(k)=1,−1
Now we simplify using product-sum logarithmic identites:
log10f(1)+log10f(2)+...+log10f(n)=log10f(1)⋅f(2)⋅...⋅f(n)=1,−1
Note that the exponent cosπ(x) is either −1 if x is odd or 1 if x is even.
Writing out the first terms we have
(2)(3)1(3)(4)(4)(5)1…
This product clearly telescopes (i.e. most terms cancel) and equals either 10 or 101. But the resulting term after telescoping depends on parity (odd/evenness), so we split it two cases, one where n is odd and another where n is even.
Case 1: Odd n
For odd n, it telescopes to 2(n+2)1 where n is clearly 3.
Case 2: Even n
For even n, it telescopes to 2n+2 where 18 is the only possible n value. Thus the answer is 021
Solution 2
Note that cos(πx) is −1 when x is odd and 1 when x is even. Also note that x2+3x+2=(x+1)(x+2) for all x. Therefore
log10f(x)=log10(x+1)+log10(x+2) if x is even
log10f(x)=−log10(x+1)−log10(x+2) if x is odd
Because of this, ∑k=1nlog10f(k) is a telescoping series of logs, and we have
k=1∑nlog10f(k)=log10(n+2)−log102=log102n+2 if n is even
k=1∑nlog10f(k)=−log10(n+2)−log102=−log102(n+2) if n is odd
Setting each of the above quantities to 1 and −1 and solving for n, we get possible values of n=3 and n=18 so our desired answer is 3+18=021