Codeforces Round #653 (Div. 3) D - Zero Remainder Array

给定一个正整数数组a和一个整数k,你需要通过增加数组元素并更新一个变量x来使得数组每个元素都能被k整除。每次操作可以将一个元素增加x并增加x的值,或者只增加x的值。求达到目标的最小操作次数。
摘要由CSDN通过智能技术生成

D. Zero Remainder Array
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an array
a
a
consisting of
n
n
positive integers.
Initially, you have an integer
x=0
x=0
. During one move, you can do one of the following two operations:
Choose exactly one
i
i
from
1
1
to
n
n
and increase
a
i
ai
by
x
x
(
a
i
:=
a
i
+x
ai:=ai+x
), then increase
x
x
by
1
1
(
x:=x+1
x:=x+1
).
Just increase
x
x
by
1
1
(
x:=x+1
x:=x+1
).
The first operation can be applied no more than once to each
i
i
from
1
1
to
n
n
.
Your task is to find the minimum number of moves required to obtain such an array that each its element is divisible by
k
k
(the value
k
k
is given).
You have to answer
t
t
independent test cases.
Input
The first line of the input contains one integer
t
t
(
1≤t≤2⋅
10
4
1≤t≤2⋅104
) — the number of test cases. Then
t
t
test cases follow.
The first line of the test case contains two integers
n
n
and
k
k
(
1≤n≤2⋅
10
5
;1≤k≤
10
9
1≤n≤2⋅105;1≤k≤109
) — the length of
a
a
and the required divisior. The second line of the test case contains
n
n
integers
a
1
,
a
2
,…,
a
n
a1,a2,…,an

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值