luogu#P5691. [NOI2001] 方程的解数

    ID: 4181 远端评测题 6000ms 500MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学2001NOI折半搜索 meet in the middle

[NOI2001] 方程的解数

Problem Description

Given an nn-variable higher-degree equation:

i=1nkixipi=0\sum\limits_{i=1}^n k_ix_i^{p_i} = 0

where x1,x2,,xnx_1, x_2, \dots, x_n are the unknowns, k1,k2,,knk_1, k_2, \dots, k_n are the coefficients, and p1,p2,,pnp_1, p_2, \dots, p_n are the exponents. All numbers in the equation are integers.

Assume the unknowns satisfy xi[1,m] (i[1,n])x_i \in [1,m] \space ( i \in [1,n]). Find the number of integer solutions to this equation.

Input Format

The first line contains a positive integer nn, the number of unknowns.
The second line contains a positive integer mm.
The next nn lines each contain two integers ki,pik_i, p_i.

Output Format

Output one line with one integer, the number of solutions of the equation.

3
150
1 2
-1 2
1 2
178

Hint

【Constraints】

For 100%100\% of the testdata, 1n61\le n \le 6, 1m1501\le m \le 150, and

i=1nkimpi<231\sum\limits_{i=1}^n |k_im^{p_i}| < 2^{31}

The answer does not exceed 23112^{31}-1, and piN[0,231)p_i \in \mathbb N^*\cap[0,2^{31}).

Translated by ChatGPT 5