Here you go.
(I just used cjbruce 's code, nothing fancy)
Btw, in case you didn't know, the % in divisions is the so called modulo operator.
In returns the rest of a division.
An example: 5 modulo 2 (5%2) would return 1, since you can put the 2 two times in the four, but you'll have one rest.
12 % 5 = 2,
66 % 10 = 6
and so on.
This is especially useful here, but generally useful, if you want to see whether a number is dividable by another number.
not work as perfect
check the game link on your pm