login
Difference between n and the largest palindrome <= n.
7

%I #26 Jun 25 2021 01:39:46

%S 0,0,0,0,0,0,0,0,0,0,1,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,

%T 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,

%U 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9

%N Difference between n and the largest palindrome <= n.

%C Up to a(301), this is the same as the sequence b(n) = least palindrome to be subtracted from n such that the difference is again a palindrome, or 10 if no such palindrome exists. But a(302) = 10 (= 302 - 292), while b(302) = 111 is the smallest palindrome P such that 302 - P is again a palindrome, 302 - 111 = 191. Similarly, b(403) = ... = b(908) = 111. For n = 1011, 1012, ..., 1110 one has a(n) = n - 1001 = 10, 11, 12, ..., 109 while b(n) = 22, 11, 44, 55, ..., 99, b(1019) = 121, b(1020) = 101, b(1021) = 22, 33, ..., 99, b(1029) = 131, 101, 10, 33, 44, ... and so on. - _M. F. Hasler_, Sep 08 2015

%C A further sequence which starts with the same values is c(n) = n-p, where p is the largest palindrome <= n such that n-p is the sum of m-1 palindromes, where m = A261675(n) is the minimal number of palindromes that add up to n. This means that c(n) = 0 (= a(n) = b(n)) if n is a palindrome; if n is the sum of 2 palindromes, then c(n) = b(n) is the smallest palindrome such that n - c(n) is again a palindrome; if n is the sum of three palindromes, then c(n) is the smallest possible sum of two palindromes such that n - c(n) is the largest possible palindrome. The numbers with A261675(n) = 3 are listed in A035137. Here, n = 1099 is the first index for which c(n) = 100 (= 99 + 1 and 1099 - 100 = 999) differs from a(n) = n - 1001 = 98 and from b(n) = 10. - _M. F. Hasler_, Sep 11 2015

%H N. J. A. Sloane, <a href="/A261424/b261424.txt">Table of n, a(n) for n = 0..20000</a>

%F a(n) = n - A261423(n). - _M. F. Hasler_, Sep 11 2015

%p # P has list of palindromes

%p palfloor:=proc(n) global P; local i;

%p for i from 1 to nops(P) do

%p if P[i]=n then return(n); fi;

%p if P[i]>n then return(P[i-1]); fi;

%p od:

%p end;

%p [seq(n-palfloor(n),n=0..200)];

%t palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d]; Table[k = n;

%t While[Nand[palQ@ k, k > -1], k--]; n - k, {n, 0, 86}] (* _Michael De Vlieger_, Sep 09 2015 *)

%Y Cf. A002113, A261423.

%K nonn,base,look

%O 0,14

%A _N. J. A. Sloane_, Aug 28 2015