Divisibility(题目地址链接:https://acs.jxnu.edu.cn/problem/NOIOPJCH0206747)

本文探讨了一种算法问题,如何通过在给定整数序列中插入运算符+或-,使其结果能被特定整数K整除。你需要编写程序解决这个问题,输入包括整数数量和K,输出为序列是否可被K整除。案例分析了17,5,-21,15序列与7和5的关系。
摘要由CSDN通过智能技术生成

描述:

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.

输入:

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.

输出:

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

样例输入:

4 7

17 5 -21 15

样例输出:

Divisible

翻译:

分割

描述:

考虑一个任意的一组整数。一个车放置+or- operators 整数中,因此不同的算法的表达评估着不同的价值。让我们,例如,操作者一系列数:17, 5, -21, 15.有八个可能的表达式:

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

我们能够说这一系列整数被K if+or-- operators 能够以某种方式被放置在这一系列的整数之间被分割的结果叫做K。在以上的例子中,这个被分成了7份(17+5+-21-15=-14)而不是5份。

你能够去写出一个程序来决定这个整数的份数。

输入:

第一行输入的包含两个整数,N和K(1<=N<=10000,2<=K<=100)被分出一个空间,第二行包含N个整数被分出的空间。每个整数不是比10000更好的。

输出:

如果给出的整数是被K分就输出单词“Divisible”,否则就输出“Not divisible”。

样例输入:

4 7

17 5 -21 15

样例输出:

Divisible

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值