import math


def _calculate_width(num_chars: int) -> int:
    """
    Calculates the width of the qr code for decoding.
    :param num_chars: The length of the ASCII QR code.
    :return: The width of the QR code.
    """
    # QR Codes are perfect squares, so calculating the square root will find the width.
    square_factor = math.sqrt(num_chars)

    if square_factor.is_integer():
        return int(square_factor)

    raise RuntimeError("No width was found for the QR code, are there trailing characters?")