It's a very nasty divisibility rule. The one for 13 works in the same way, but instead of multiplying by 2, you multiply by 4.
There are actually a couple of well-known rules for that, but these are the easiest to remember IMO.
Well, on the side of easy ones there is "if the last digit is divisible by 2, whole number is divisible by 2". Also works for 5. And if you take last 2 digits, it works for 4. And the legendary "if it ends with 0, it's divisible by 10".
Forming an alternating sum of blocks of three from right to left gives a multiple of 7
299,999 would be 999 - 299 = 700 which is divisible by 7. And if we simply swap grouped digits to 999,299, it is also divisible by 7 since 299 - 999 = -700.
And as for 13:
Form the alternating sum of blocks of three from right to left. The result must be divisible by 13
So we have 999 - 999 + 299 = 299.
You can continue with other rules so we can then take this
Add 4 times the last digit to the rest. The result must be divisible by 13.
So for 299 it's 29 + 9 * 4 = 65 which divides by 13. Pretty cool.
With 17, I understand that you're referring to how 299,999 is also divisible by 17. What is the 51 reference, though? I know there's 3,999,999,999,999 but that starts with a 3. Not the same at all.
So what? Being a prime number doesn't mean it can't be a divisor. Or is it the string of 9s that's supposed to be upsetting? Why? What difference does it make?
Caught me… A pretty quick way to see this and the title is using Fermat’s little theorem which states that k^(p-1) ~ 1 mod p for nonzero k. Using this we can write
3*10^5 ~ 3^6 ~ 1 mod 7
and
3*10^8 ~ 3*(-3)^8 ~ 3^9 ~ 16^9 ~ 2^36 ~ (212)3 ~ 1^3 ~ 1 mod 13