#P5691. Counting Solutions of an Integer Polynomial Equation

    ID: 18919 Type: Default 1000ms 256MiB

Counting Solutions of an Integer Polynomial Equation

Counting Solutions of an Integer Polynomial Equation

Given an integer polynomial equation in n variables:

$$\sum_{i=1}^{n} k_i x_i^{p_i} = 0$$

Here, the unknowns x1, x2, \dots, xn satisfy 1 \leq x_i \leq m for all 1 \leq i \leq n, the coefficients k1, k2, \dots, kn and the exponents p1, p2, \dots, pn are all integers. Determine the number of integer solutions of the equation that satisfy these conditions.

inputFormat

The input consists of three lines:

  • The first line contains two integers n and m.
  • The second line contains n integers representing the coefficients: k1, k2, \dots, kn.
  • The third line contains n integers representing the exponents: p1, p2, \dots, pn.

outputFormat

Output a single integer: the number of solutions in which the equation holds true.

sample

2 10
1 -1
1 1
10