Loading Now

nthDerivative

Write a function which computes the nthderivative of a polynomial evaluated at a point, modulo 109 + 7. The output should be in the range [0, 109 + 7).

Example: 

  • For coefficients = [3, 2, 1, 1] , n = 2 and x = 100, the output should be nthDerivative(coefficients, n, x) = 602.
    The polynomial represented here is f(x) = 3 + 2x + x2 + x3, which has a second derivative of f''(x) = 2 + 6x. Therefore, the answer is f''(100) = 602.

Input/Output

  • [execution time limit] 0.5 seconds 

  • [input] array.integer coefficients

    The coefficients of the polynomial, where coefficients[i] is the coefficient of xi.

    Guaranteed constraints:
    0 ≤ coefficients.length ≤ 5000.

  • [input] integer n

    The number of derivatives to take before evaluating.

    Guaranteed constraints:
    0 ≤ n ≤ 1000.

  • [input] integer x

    The value at which to evaluate the nthderivative.

    Guaranteed constraints:
    -1000 ≤ x ≤ 1000.

  • [output] integer

    • The nth derivative of the polynomial defined by coefficients evaluated at xreduced modulo 109 + 7. The output should be in the range [0, 109 + 7).

Post Comment

Contact