For the value of n, we have 3 choices

**Case 1 : n % 3 = 1**

Let,

P = (n^{2}+2) % 3

P = ( ( n^{2} ) % 3 + 2 % 3 ) % 3

P = ( ( n % 3 ) ( n % 3 ) + 2 ) % 3

P = ( 1 * 1 + 2 ) % 3

P = 3 % 3

P = 0

Therefore, n^{2}+2 is divisible by 3 if n % 3 = 1

**Case 2 : n % 3 = 2**

Let,

P = (n^{2}+2) % 3

P = ( ( n^{2} ) % 3 + 2 % 3 ) % 3

P = ( ( n % 3 ) ( n % 3 ) + 2 ) % 3

P = ( 2 * 2+ 2 ) % 3

P = 6 % 3

P = 0

Therefore, n^{2}+2 is divisible by 3 if n % 3 = 2

**Case 2 : n % 3 = 0**

P = (n^{2}+2) % 3

P = ( ( n^{2} ) % 3 + 2 % 3 ) % 3

P = ( ( n % 3 ) ( n % 3 ) + 2 ) % 3

P = ( 0 * 0+ 2 ) % 3

P = 2

Therefore, n^{2}+2 is not divisible by 3 if n % 3 = 0

From above cases, we can conclude that n^{2}+2 is divisible by 3 if and only if n is not divisible by 3.