def efficient_multiplication_count(x: int, n: int) -> int:
    """
    An efficient way to count the number of appearances of a number x in the multiplication table for [1,n] x [1,n].
    Since the table is symmetric due to commutativity of integer multiplication, we only need to consider factors a and
    b of x when a <= b and add them twice (a * b and b * a) unless x is square and a == b, in which case, we only add
    them once.
    :param x: the product to search for
    :param n: the size of the table
    :return: the number of unique products that give x

    >>> [efficient_multiplication_count(i, 5) for i in range(1, 26)]
    [1, 2, 2, 3, 2, 2, 0, 2, 1, 2, 0, 2, 0, 0, 2, 1, 0, 0, 0, 2, 0, 0, 0, 0, 1]

    >>> [efficient_multiplication_count(i, 6) for i in range(1, 37)]
    [1, 2, 2, 3, 2, 4, 0, 2, 1, 2, 0, 4, 0, 0, 2, 1, 0, 2, 0, 2, 0, 0, 0, 2, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1]
    """
    occurrences = 0

    # The lower bound for a factor is x / n or n, as for anything lower, there aren't entries high enough in the table
    # to multiply by to get n.
    a = x // n + (1 if x % n else 0)
    b = x // a + (1 if x % a else 0)
    a = min(a, b)

    # We only count entries x = a * b for a <= b.
    # This reflects the diagonal symmetry of the board due to commutativity of integers.
    while True:
        b, r = divmod(x, a)

        # Now terminate prematurely if a > b.
        if a > b:
            break

        # If this is a factor, count it.
        # If it is not on the main diagonal (i.e. x is not a square), count it twice to account for a * b and b * a.
        # If it is on the main diagonal (i.e. x is a square, and a == b), count it once to account for a * a.
        if r == 0 and b <= n:
            occurrences += 1 if a == b else 2

        a += 1

    return occurrences