POJ1745解题报告

来源:互联网 发布:python 多线程 sleep 编辑:程序博客网 时间:2024/06/05 11:50
Divisibility
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6873 Accepted: 2294

Description

Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us, for example, take the sequence: 17, 5, -21, 15. There are eight possible expressions: 17 + 5 + -21 + 15 = 16
17 + 5 + -21 - 15 = -14
17 + 5 - -21 + 15 = 58
17 + 5 - -21 - 15 = 28
17 - 5 + -21 + 15 = 6
17 - 5 + -21 - 15 = -24
17 - 5 - -21 + 15 = 48
17 - 5 - -21 - 15 = 18
We call the sequence of integers divisible by K if + or - operators can be placed between integers in the sequence in such way that resulting value is divisible by K. In the above example, the sequence is divisible by 7 (17+5+-21-15=-14) but is not divisible by 5.

You are to write a program that will determine divisibility of sequence of integers.

Input

The first line of the input file contains two integers, N and K (1 <= N <= 10000, 2 <= K <= 100) separated by a space.
The second line contains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value.

Output

Write to the output file the word "Divisible" if given sequence of integers is divisible by K or "Not divisible" if it's not.

Sample Input

4 717 5 -21 15

Sample Output

Divisible
题意:给定n个数和一个K,问这n个数通过加减得到的结果能不能被K整除
思路:自己想了一会,发现只需要记住当前i步所有变换%k能得到的余数,在用第i+1个数在第i步得到所有余数的基础上再得到i+1步所有
的余数(i=0...i=n-1),最后判断是否能得到余数0即可。。