P1356 integer number of columns

Title Description

For any integer sequence, we can put any intermediate each two integers a symbol '+' or '-', which can form an expression, it can calculate the value of the expression. For example, there is now an integer sequence: 17,5, -2, -15, it can be constructed expression 8:

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

For an integer sequence, we constructed a method as above through a different expression, resulting in a different value, if the value can be divided by k, then we say that the number of columns k be divisible. In the above example, the number of columns can be divisible by 7 (17 + 5 + (- 21) = -15 --14), but can not be divisible by 5. Now your task is to determine whether a number of columns that can be a number divisible.

Input Format

The first row is an integer m, m expressed subtasks. Then there is the description m tall task. There are two lines of each sub-task. The first line is two integers n and k (1 <= n <= 10000, 2 <= k <= 100), n and k have a middle space. n represents the number of integers in the number of columns; k is the number you need to judge whether the column k be divisible. The second line is an integer number n columns, separated by a space between the integer, the absolute value of each number is not more than 10,000.

Output Format

Output file should m row, followed by the corresponding m sub-task input file, if the number is divisible by k columns can be output "Divisible", otherwise output "Not divisible", end of the line the first line should be no spaces.

Sample input and output

Input # 1
2

4 7

17 5 -21 15

4 5

17 5 -21 15

Output # 1
Divisible

Not divisible

Thinking

violence. . .

Being interpreted as number theory we can use the rand random number generation to determine that the + or -, as long as random a few times, you can AC. . . (Themselves do not know how unconscionable violence also cheat points ...)

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=10010;

int m,n,k,s;
int a[N],j,p;

int main() {
	scanf("%d",&m);
	while(m--) {
		scanf("%d%d",&n,&k);
		for(int i=1; i<=n; i++)
			scanf("%d",&a[i]);
		j=250;
		while(j--) {
			s=0;
			for(int i=1; i<=n; i++) {
				p=rand();
				if(p%2)
					s+=a[i];
				else
					s-=a[i];
			}
			if(!(s%k)) {
				printf("Divisible\n");
				k=0;
				break;
			}
		}
		if(k)
			printf("Not divisible\n");
	}
	return 0;
}

 

Guess you like

Origin www.cnblogs.com/mysh/p/11800484.html