import math


def number_payments(A, i, P):
    """Finding the number of payments using:
    A = annuity payment
    P = credit principal
    i = nominal (monthly) interest rate (float, not a percentage)
    Returns formatted "It will take Y years and X months" string.
    """
    A = int(A)
    P = int(P)
    i = float(i) / (100 * 12)
    num_payments = math.ceil(math.log(A / (A - (i * P)), (1 + i)))
    # Convert to years and months
    years = num_payments // 12
    months = num_payments % 12
    if years == 0:
        string_y = ''
    elif years == 1:
        string_y = f'{years} year'
    else:
        string_y = f'{years} years'

    if months == 0:
        string_m = ''
    elif months == 1:
        string_m = f'{months} month'
    else:
        string_m = f'{months} months'

    if (len(string_y) > 0) and (len(string_m) > 0):
        res = string_y + ' and ' + string_m
    else:
        res = string_y + string_m

    overpayment = (num_payments * A) - P
    res = f'It will take {res} to repay this credit\nOverpayment = {overpayment}'
    return res