OFFSET
0,2
COMMENTS
Difference between the multiples of 3 (A008585) and the closest multiple of 19 (A008601). For any two numbers (in this case p=3 and q=19), a sequence is produced consisting of a palindrome cycle. If p and q are coprime, then the cycle length is equal to max(p,q). The biggest number in the sequence will be at most half of max(p,q). Here is a plot of the first cycle of this sequence:
9 X X
8 X X
7 X X
6 X X
5 X X
4 X X
3 X X
2 X X
1 X X
0 X X
LINKS
Index entries for linear recurrences with constant coefficients, signature (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1).
FORMULA
a(n) = a(n-19). - David A. Corneth, Oct 14 2024
a(n) = min(3*n-19*floor(3*n/19), 19*ceil(3*n/19)-3*n).
MATHEMATICA
LinearRecurrence[{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 3, 6, 9, 7, 4, 1, 2, 5, 8, 8, 5, 2, 1, 4, 7, 9, 6, 3}, 96] (* James C. McMahon, Oct 31 2024 *)
PROG
(C)
int p = 3;
int q = 19;
for (int t = 0; t <= 99; t++) {
int closest = 999;
for (int i = 0; i <= 99; i++) {
int dist=abs(i * q - t * p);
if (dist < closest) {
closest = dist;
}
}
printf("%i, ", closest);
}
(PARI) a(n) = my(n3 = 3*n); min(n3 - 19*floor(n3/19), ceil(19*ceil(n3/19) - n3)) \\ David A. Corneth, Oct 14 2024
(Python)
def A377030(n): return (0, 3, 6, 9, 7, 4, 1, 2, 5, 8, 8, 5, 2, 1, 4, 7, 9, 6, 3)[n%19] # Chai Wah Wu, Oct 31 2024
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Neil Vaughan, Oct 13 2024
STATUS
approved
