import math


def pressure_final(p0, M, lambda_res, Tsr, Z, R, d, x):
    """
    :param p0: Absolute natural gas pressure at the beginning of the pipe, Pa
    :param M: Mass flow of the natural gas, kg/c
    :param lambda_res: Hydraulic resistance coefficient, dimensionless
    :param Tsr: Medium temperature of natural gas, K
    :param Z: Compressibility factor of natural gas at medium parameters
    :param R: Gas constant of natural gas, J/(kg*K)
    :param d: Inner diameter of pipe, m
    :param x: Length of pipe section, m
    :return: Final absolute pressure pk, Pascal
    """
    return math.sqrt((p0 ** 2) - (16 * (M ** 2) * lambda_res * Z * R * Tsr * x) / (math.pi**2 * d**5))