"R.Radhakrishnan" : > After following this thread with interest for a while, may I point out the > following tests: > > Divisible (evenly) by: Test ... > I never found a way to test for divisibility by 7, though i spent many mis-spent > hours in my youth trying! Group the digits six and six, and add them up. If the result is divisible by 7, so is the original number. Example: 123456789 -> 123 + 456789 = 456912 = 65273 * 7 + 1, so 123456789 is not divisible by 7. A sixdigit number can be checked for divisibility by 7 as follows: Subtract the first three digits from the last three: 456912 -> 912-456 = 456. Multiply the first digit by 9 and the second digit by 3, add them up, and repeat until obviously divisible or indivisible by 7. 456 -> 9*4+3*5+6 = 36+15+6 = 57 -> 3*5 + 7 = 22 -> 3*2+1 -> 8 = 7+1. In general, suppose the period of the rational number 1/n is p (p=6 for n=7). You can test for divisibility by n by taking groups of p digits and adding them up. Mathematically, the idea is that x mod n = (x mod (10^p-1)) mod n, since n is a divisor of 10^p-1. We don't have to use exactly 10^p-1, but any modulus that is divisible by n can be used. The example above for seven used the moduli 999999, 1001 (=143*7), and 7. Incidentally, divisibility by 7 is much simpler in binary than base 10 since 1/7 = 0.001001001001... binary, and p=3, so checking is very easy. Cheers, -- Martin Martin Nilsson http://www.sics.se/~mn/ Swedish Institute of Computer Science E-mail: mn@sics.se Box 1263, S-164 28 Kista Fax: +46-8-751-7230 Sweden Tel: +46-8-752-1574