OFFSET
4,1
COMMENTS
To determine if N is divisible by p: Write N=10*M+D, where D=ones digit of N and M=N without ones digit. Then N is divisible by p iff M+c(p)*D is.
c(p) is the multiplicative inverse of 10 (mod p) with the smallest absolute value. (But note that the link below uses c(13)=9 rather than -4.)
For a given n, a(n) is either -A103876(n) or prime(n)-A103876(n), whichever has a smaller absolute value. - Nicholas Stefan Georgescu, Jan 18 2023
LINKS
Ethan Magness, Steven Sinnott and Robert L. Ward, Divisibility Rules
EXAMPLE
The first few terms are c(7)=-2, c(11)=-1, c(13)=4. To find out if a number is divisible by 7, take the last digit, double it and subtract the result from the rest of the number. If you get an answer divisible by 7 (including 0), then the original number is divisible by 7. If you do not know the new number's divisibility, you can apply the rule again. Example: If you had 203, you would subtract 2*3=6 from 20 to get 14; since 14 is divisible by 7, so is 203.
MATHEMATICA
c[p_] := If[(v=PowerMod[10, -1, p])>p/2, v-p, v]; c/@Prime/@Range[4, 100]
PROG
(Python)
import sympy
[(pow(10, -1, p))-p*(p%10%6==1) for p in sympy.primerange(7, 300)]
# Nicholas Stefan Georgescu, Jan 18 2023
(PARI) a(n) = centerlift(Mod(1, prime(n))/10); \\ Kevin Ryde, Feb 18 2023
CROSSREFS
KEYWORD
sign,base
AUTHOR
Devora Rahav (rahav-d(AT)inter.net.il), Dec 09 2002
EXTENSIONS
Edited by Dean Hickerson, Dec 23 2002
STATUS
approved