You didn't say, but the only way this works is if n is an integer. Use the modulo function. returns the remainder when n is divided by m. For positive integers, the range of the modulo function is , therefore for , the range is .
So there are three possibilities regardless of the value of n:
For each of the three possibilities, there is only one 0 result, hence only one of the numbers is divisible by 3.
If n is a negative integer, the range of is and the result is the same.