result = n % 3;
if( result < 0 ) result += 3;
Don’t perform extra mod operations as suggested in the other answers. They are very expensive and unnecessary.
result = n % 3;
if( result < 0 ) result += 3;
Don’t perform extra mod operations as suggested in the other answers. They are very expensive and unnecessary.