The modulus operator could be useful here.