There is a simple technique I read about long time back. This should help with most divisibility tests(including 7 and 13)
Let ABCDE be the number that we want to check for divisibility by 7,
Now consider ABCDE = 10 ^ 4 * A + 10 ^ 3 * B + 10 ^ 2 * C + 10 * D + E
If (ABCDE % 7 == 0)
=> ((ABCDE + N * 7) % 7 == 0) for all N
=> (ABCDE - 21(or 91 or + 49 )* E * 7) % 7 == 0.
=> Thus ABC(D-2E)0 % 7 == 0
=> (10 *(ABC(D-2E))) % 7 == 0
=> ABC(D-2E) % 7 == 0 //Since 10 and 7 are co prime
Thus we have reduced the number of digits. Similarly with 13 we need to add 3 times the last digit to the remaining number and check for divisibility.
This helps in a lot of cases
Hmm if you know the proof a small hint would be nice. I have spent quite a bit of time on this already, without any success
There is a theorem known as Fermat's Theorem (which is a special case of Euler's Theorem), which goes like this: If p is prime and p is not a factor of positive integer A, then
A^(p-1) is congruent to 1 modulus p.
That is,
{[A^(p-1)] - 1} % p == 0.
Assume p is different from 2 and 5, as these primes already have divisibility tests.
Now consider an (n+1)-digit number X, written in base 10 as
<a(n),a(n-1),a(n-2), ... ,a(2),a(1),a(0)>.
So, X = sigma{(a(j)*(10^j) as j runs from 0 to n}.
Now, for each j, divide 10^j by p, and note the remainder (10^j)%p.
For each j, {(10^j)%p} == {(10^(p-1+j))%p}
[[See the proof below]
]
So, the remainders repeat cyclically with a period of p. So, if we denote these p remainders as r(j), where j runs from 0 through n, then the divisibility test goes like this:
<a(n),a(n-1),a(n-2), ... ,a(2),a(1),a(0)> is divisible by prime p if and only if
sigma{(a(j)*r(j) as j runs from 0 to n} is divisible by p.
Note that the number of remainders, which is of course p, is known as soon as p is given.
Proof of Above Claim:
Suppose p is different from 2 and 5. Then, by Fermat, p divides {(10^(p-1) - 1}.
So, p also divides (10^j)*{(10^(p-1)) - 1}=={(10^(p-1+j)) - 10^j}.
There exist integers S and T such that
(10^(p-1+j) ) = S*p + {(10^(p-1+j))%p},
(10^j) = T*p + {(10^j)%p}.
Obviously p must divide the difference between the two above, hence the result. Note that the remainders must be less than p. (Work it in detail and think about it.)