Vincenzo Manto

A395743

Created: 5/19/2026 | Author: Vincenzo Manto and James C. McMahon , May 05 2026

Sum of the cumulative number of previous occurrences of the digits of n in the sequence 1..n excluding the current occurrence of each digit.

This sequence is the exclusive counterpart to A343644. While A343644 counts the occurrences of digits in the range [1,n], a(n) counts only the occurrences strictly preceding each digit of n. Formally a(n) = A343644(n) - A055642(n). Thus, this sequence represents the exclusive scan of digit occurrences, whereas A343644 is the inclusive scan. a(n) = 0 for all single-digit n as it measures the cumulative repetition of digits at the exact moment n is formed.

Sequence Chart

Graph of A395743

Data

0,0,0,0,0,0,0,0,0,1,5,5,6,7,8,9,10,11,12,3,15,9,8,9,10,11,12,13,14,5,17,18,13,11,12,13,14,15,16,7,19,20,21,17,14,15,16,17,18,9,21,22,23,24,21,17,18,19,20,11,23,24,25,26,27,25,20,21,22,13

Formula

a(n) = Sum_{i=1..k} C(d_i), where d_1, d_2, ..., d_k are the digits of n, and C(d_i) is the number of times digit d_i has appeared in the concatenation of all integers from 1 to n-1 plus the digits of n to the left of d_i.

a(n) = A343644(n) - A055642(n).

Computational Implementations

PYTHON

def generate_sequence(limit):
    seq = []
    counts = [0] * 10
    for n in range(1, limit + 1):
        v = 0
        s = str(n)
        for char in s:
            d = ord(char) - 48
            v += counts[d]
            counts[d] += 1
        seq.append(v)
    return seq
print(generate_sequence(70))

Mathematica

a[n_]:=Module[{sm=0,id=IntegerDigits[n],d=IntegerDigits/@Range[n-1]//Flatten},Do[sm=sm+Count[Join[d,Take[id,i-1]],id[[i]]],{i,IntegerLength[n]}];sm];Array[a,70]

Cross-References

See also OEIS entries: Cf. A007953, A343644, A055642.