def partition_prefix_length(n: int) -> int:
    """
    For a given number of subgraphs, return a partition prefix length that
    yields at most 512 subgraphs per partition.

    >>> [partition_prefix_length(n) for n in (0, 1, 512, 513, 16 * 512, 16 * 513 )]
    [0, 0, 0, 1, 1, 2]
    """
    return 1 + partition_prefix_length(n // 16) if n > 512 else 0