Number of Beautiful Pairs
Count first digits seen so far, then for each new number add the earlier first digits that are coprime with its last digit.
Count first digits seen so far, then for each new number add the earlier first digits that are coprime with its last digit.