OFFSET
1,9
COMMENTS
k is an integer that minimizes |k*p1-p2|. It is trivial that if j is the integer part of p2/p1, k is either j or j+1.
LINKS
Lei Zhou, Table of n, a(n) for n = 1..10000
EXAMPLE
MATHEMATICA
NumDiff[n1_, n2_] := Module[{c1 = n1, c2 = n2}, If[c1 < c2, c1 = c1 + c2; c2 = c1 - c2; c1 = c1 - c2]; k = Floor[c1/c2]; a1 = c1 - k*c2; If[a1 == 0, a2 = 0, a2 = (k + 1) c2 - c1]; Return[Min[a1, a2]]];
p1 = 2; p2 = 1; Table[p2 = NextPrime[p2]; If[p2 > p1, p1 = p2; p2 = 2]; NumDiff[p1, p2], {n, 1, 100}]
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Lei Zhou, Feb 02 2015
STATUS
approved