A number is divisible by 3 iff the sum of its digits is divisible by 3. Of course, you can use this rule again to decide about the sum of the digits, if it's still too large. In fact, it is true that the remainder of the digit sum after division by 3 is equal to the remainder of the number.

Actually, a similar rule can be formulated for any divisor (although it won't be nearly as elegant); see the set of decimal representations of numbers divisible by 17 is regular for an example.


C++ has its own "rule of three": These three methods

go together. If you write one, you probably need to write all three!

Why? You need one of these methods when your object "owns" something. If an object owns something, care must be taken in copying it and assigning it (do we want to end up with two objects owning the same thing?) and in destroying it (what happens to what the late object used to own?). Interestingly, almost all uses for these 3 methods is related to ownership. So if you need to write one, you (probably) need to write all three.