import math


def get_table_rows_cols(num_tiles, row_col_delta=2):
    """
    Given a number of tiles for a table, calculate the necessary dimensions of
    the table with a preference for dimensions with smaller differences
    """
    num_tiles_root = math.sqrt(num_tiles)
    if num_tiles_root.is_integer():
        # perfect square table
        n_rows = n_cols = int(num_tiles_root)
    else:
        # find factors of num_tiles, if a pair of factors have a delta that is
        # within row_col_delta then set the pair as the (row, col) dimensions,
        # otherwise round up to the next perfect square and use the root to
        # make a square table
        n_rows = n_cols = math.ceil(num_tiles_root)
        for i in range(2, math.ceil(num_tiles_root)):
            if num_tiles % i == 0:
                pair = num_tiles // i
                if pair - i <= row_col_delta:
                    n_rows = pair
                    n_cols = i

    return n_rows, n_cols