#P1356. 数列的整除性

    ID: 353 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp数学福建省历届夏令营

数列的整除性

Description

For any integer sequence, we can insert either the symbol + or - between every two integers to form an expression, and thus compute its value. For a given integer sequence, we can construct different expressions in this way and obtain different values. If any one of these values is divisible by kk, we say the sequence is divisible by kk. Your task is to determine whether a given sequence is divisible by a given number.

Input Format

This problem has multiple test cases.

The first line contains an integer MM, the number of test cases.

For each test case:

  • The first line contains two integers nn and kk, where nn is the number of integers in the sequence.
  • The second line contains nn integers, which form the input sequence {ai}\{a_i\}.

Output Format

Output MM lines, each corresponding to a test case in the input. If the sequence is divisible by kk, output Divisible; otherwise, output Not divisible. There should be no leading or trailing spaces on the line.

2
4 7
17 5 -21 15
4 5
17 5 -21 15

Divisible
Not divisible


Hint

Explanation for Sample 1

For the integer sequence 17,5,21,1517, 5, -21, 15, we can construct 88 expressions:

  • 17+5+(21)+15=1617+5+(-21)+15=16.
  • 17+5+(21)15=1417+5+(-21)-15=-14.
  • 17+5(21)+15=5817+5-(-21)+15=58.
  • 17+5(21)15=2817+5-(-21)-15=28.
  • 175+(21)+15=617-5+(-21)+15=6.
  • 175+(21)15=2417-5+(-21)-15=-24.
  • 175(21)+15=4817-5-(-21)+15=48.
  • 175(21)15=1817-5-(-21)-15=18.

This sequence is divisible by 77 (17+5+(21)15=1417+5+(-21)-15=-14), but not divisible by 55.

Constraints For all test points, it is guaranteed that 1M201 \le M \le 20, 1n1041 \le n \le 10^4, 2k1002 \le k \le 100, and ai104\left| a_i \right| \le 10^4.

  • upd 2022.9.27\text{upd 2022.9.27}: Added one Hack testdata set.
  • upd 2023.11.29\text{upd 2023.11.29}: Added one Hack testdata set.

Translated by ChatGPT 5