description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
test_case = int(input())
for _ in range(test_case):
n, k = map(int, input().split())
ar = list(map(int, input().split()))
mp = {}
for i in ar:
calc = i % k
if calc:
calc = k - calc
mp.setdefault(calc, 0)
mp[calc] += 1
if len(mp) == 0:
print(0)
continue
max_value_key = max(mp, key=lambda k: mp[k])
max_value_key = mp[max_value_key]
val = 0
for key, value in mp.items():
if value == max_value_key:
val = max(key, val)
max_value_key = val
print((mp[max_value_key] - 1) * k + max_value_key + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t:
line = input().split()
n, k = int(line[0]), int(line[1])
a = input().split()
a = list(map(int, a))
d = {}
for i in range(n):
a[i] = (k - a[i] % k) % k
if a[i] != 0:
if a[i] not in d:
d[a[i]] = 0
d[a[i]] += 1
if len(d):
d = list(d.items())
d.sort(key=lambda x: x[1])
ans = (d[-1][1] - 1) * k
mi = -1
for i in range(len(d)):
if d[i][1] == d[-1][1]:
if mi == -1 or d[i][0] > d[mi][0]:
mi = i
ans += d[mi][0] + 1
print(ans)
else:
print(0)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
tcs = int(input())
for tc in range(tcs):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
d = dict()
x = 0
for a in arr:
if a % k != 0:
c = k - a % k
if c in d:
d[c] += 1
else:
d[c] = 1
max_k = max_v = 0
for key in sorted(list(d.keys())):
if d[key] >= max_v:
max_v = d[key]
max_k = key
if max_k == 0:
print(0)
else:
print(k * (max_v - 1) + max_k + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solve():
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
pq = []
for e in a:
if e % k == 0:
continue
pq.append(k - e % k)
pq.sort()
q = []
p = 0
level = 1
for e in pq:
if e == p:
level += 1
else:
level = 1
q.append((level, e))
p = e
q.sort()
return 0 if len(q) == 0 else (q[-1][0] - 1) * k + q[-1][1] + 1
T = int(input())
for case in range(T):
print(solve())
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def compute(n, k, arr):
cnt = 0
cur = k
for i in range(n):
arr[i] = arr[i] % k
arr.sort()
for i in range(n):
if arr[i] % k != 0:
temp = k - arr[i] % k
if i > 0 and arr[i - 1] == arr[i]:
cnt = max(temp + cur + 1, cnt)
cur += k
else:
cur = k
cnt = max(temp + 1, cnt)
return cnt
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(compute(n, k, arr))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
ar = [int(i) for i in input().split()]
for x in range(n):
ar[x] = ar[x] % k
ar.sort()
freq = {}
check = 0
for item in ar:
if item == 0:
pass
elif item in freq:
freq[item] += 1
else:
freq[item] = 1
check += 1
if check == 0:
print(0)
else:
Keymax = max(freq, key=freq.get)
print(k * (ar.count(Keymax) - 1) + k - Keymax + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = {}
for i in range(len(a)):
if a[i] % k != 0:
if b.get(k - a[i] % k) == None:
b[k - a[i] % k] = 1
else:
b[k - a[i] % k] += 1
mx = 0
index = -1
for key in b:
if b[key] >= mx:
if mx != b[key] or key > index:
mx = b[key]
index = key
if index == -1:
print(0)
return
print(index + (mx - 1) * k + 1)
return
def test():
t = int(input())
while t:
main()
t -= 1
test()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR NONE ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def zerorem(n, k, array):
a = []
for y in array:
if y % k != 0:
a.append(k - y % k)
if a == []:
return 0
maxcount = None
maxcountn = None
dic = {}
for x in a:
if x in dic:
dic[x] += 1
else:
dic[x] = 1
if maxcount == None:
maxcount = dic[x]
maxcountn = x
if dic[x] > maxcount:
maxcount = dic[x]
maxcountn = x
elif dic[x] == maxcount:
if maxcountn < x:
maxcountn = x
if maxcount == 1:
return max(a) + 1
else:
return (maxcount - 1) * k + maxcountn + 1
t = int(input())
a = []
for i in range(t):
n, k = list(map(int, input().split(" ")))
array = list(map(int, input().split(" ")))
a.append([n, k, array])
for x in a:
print(zerorem(*x))
|
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR LIST RETURN NUMBER ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t > 0:
t = t - 1
n, k = map(int, input().split())
a = input()
A = list(map(int, list(a.split())))
d = {}
for i in range(n):
y = A[i] % k
if y in d:
d[y] = d[y] + 1
else:
d[y] = 1
m = 0
e = 0
for i in d:
if i != 0:
if m < d[i]:
m = d[i]
e = i
if m == d[i]:
if i < e:
e = i
if e == 0:
print(0)
else:
b = k - e
c = k - e + (m - 1) * k + 1
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
l1 = [0] * n
for i in range(n):
if l[i] % k != 0:
o = l[i] // k + 1
l1[i] = o * k - l[i]
l1.sort()
s = l1[0]
p = 0
for i in range(1, n):
if l1[i] > 0:
if l1[i] > l1[i - 1]:
s = l1[i]
else:
s = k + s
p = max(p, s)
if p == 0:
if len(l1) == 1 and l1[0] != 0:
print(l1[0] + 1)
else:
print(0)
else:
print(p + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
rem = dict()
for i in range(n):
if arr[i] % k != 0:
if arr[i] % k not in rem:
rem[arr[i] % k] = 1
else:
rem[arr[i] % k] += 1
m = 0
for x in rem:
t = k - x + k * (rem[x] - 1) + 1
if t > m:
m = t
print(m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = set()
mxi = {}
arr = map(int, input().split())
for x in arr:
m = x % k
if m != 0:
m2 = k - m
if m not in mxi.keys():
mxi[m] = m2
else:
m2 = mxi[m] + k
mxi[m] += k
s.add(m2)
ans = 0
flist = list(s)
list.sort(flist)
if len(flist) != 0:
ans = flist[-1] + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
d = {}
ans = 0
for i in map(int, input().split()):
if i % k:
d[i % k] = d.get(i % k, 0) + 1
ans = max(ans, k * d[i % k] - i % k + 1)
print(ans)
|
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for t in range(int(input())):
n, k = map(int, input().split())
a = [(k - int(x) % k) for x in input().split()]
freq = {}
for x in a:
if x < k:
freq[x] = freq.get(x, 0) + 1
if len(freq):
most_freq = max(freq.values())
last_guy = max([a for a, b in freq.items() if b == most_freq])
print(k * (most_freq - 1) + last_guy + 1)
else:
print(0)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = []
for num in a:
if num % k != 0:
rem = (num // k + 1) * k - num
mod.append(rem)
if len(mod) == 0:
print(0)
continue
have_seen = dict()
ans = 0
for rem in mod:
if rem not in have_seen:
ans = max(rem, ans)
have_seen[rem] = rem
else:
new_rem = have_seen[rem] + k
ans = max(ans, new_rem)
have_seen[rem] = new_rem
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def f():
n, k = map(int, input().split())
a = sorted([(k - int(x) % k) for x in input().split()])
ind = n
for i in range(n - 1, -1, -1):
if a[i] == k:
ind -= 1
a = a[:ind]
d = {}
mx = 0
if len(a) == 0:
print(0)
return
for i in a:
if i not in d.keys():
d[i] = 1
else:
d[i] += 1
if d[i] >= mx:
mx = d[i]
numb = i
print(k * (mx - 1) + numb + 1)
t = int(input())
for i in range(t):
f()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t > 0:
t -= 1
n, k = map(int, input().split())
a = list(map(int, input().split()))
left = []
for i in a:
if i % k != 0:
left.append(i % k)
if len(left) == 0:
print(0)
continue
left.sort()
count = {}
for i in left:
count[i] = count.get(i, 0) + 1
max = 0
x = -1
for i in left:
if max < count[i]:
x = i
max = count[i]
ans = k * (max - 1) + k - x + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t > 0:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
d = {}
for num in arr:
d[num % k] = d.get(num % k, 0) + 1
ans = 0
for key in d.keys():
if key != 0:
freq = d[key]
tempAns = freq * k - key
ans = max(ans, tempAns)
print(ans + 1 if ans != 0 else ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
r = list(map(int, input().split()))
res = []
for i in range(0, len(r)):
a = k - r[i] % k
if a != k:
res.append(a)
if not res:
print(0)
else:
res.sort()
result = []
c = 0
for i in range(0, len(res)):
if i > 0:
if res[i] == res[i - 1]:
result[-1] = result[-1] + k
else:
result.append(res[i])
else:
result.append(res[i])
print(max(result) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
def answer(n, k, a):
mk = [((k - a[i] % k) % k) for i in range(n)]
mk.sort()
x = 0
nindx = 0
mknodup = [mk[0]]
for i in range(1, n):
if mk[i] == 0:
mknodup.append(0)
elif mk[i] == mk[nindx]:
mknodup.append(mk[i] + (i - nindx) * k)
else:
mknodup.append(mk[i])
nindx = i
mknodup.sort()
if mknodup[-1] == 0:
return 0
else:
return mknodup[-1] + 1
return
def main():
t = int(input())
while t:
n, k = [int(i) for i in sys.stdin.readline().split()]
a = [int(i) for i in sys.stdin.readline().split()]
print(answer(n, k, a))
t -= 1
return
main()
|
IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER NUMBER RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
[n, k] = list(map(int, input().split()))
A = list(map(int, input().split()))
D = {}
S = set()
j = 0
while j < len(A):
A[j] = A[j] % k
j += 1
D = dict.fromkeys(A, 0)
ans = 0
for a in A:
if a == 0:
continue
ans = max(ans, D[a] * k + (k - a) + 1)
D[a] += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
m = {}
max_mod, max_i = -1, -1
a = list(map(int, input().split()))
for i in range(n):
x = a[i]
if x % k not in m:
m[x % k] = 0
m[x % k] += 1
if x % k == 0:
continue
if m[x % k] > max_mod or m[x % k] == max_mod and x % k < max_i:
max_mod = m[x % k]
max_i = x % k
if max_mod == -1:
print(0)
else:
print((max_mod - 1) * k + (k - max_i) + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
temp = dict()
ans = 0
for i in a:
if i % k != 0:
rem = k - i % k
if rem in temp.keys():
temp[rem] += 1
else:
temp[rem] = 1
for i in temp.keys():
ans = max(ans, i + k * (temp[i] - 1))
if ans != 0:
ans = ans + 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for l in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = {}
c = {}
s = 0
for i in range(n):
a[i] = a[i] % k
if a[i] == 0:
continue
else:
if a[i] in c:
c[a[i]] += 1
else:
c[a[i]] = 0
m[a[i]] = c[a[i]] * k + k - a[i]
s = max(s, m[a[i]])
if s == 0:
print(0)
else:
print(s + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def keywithmaxval(d):
v = list(d.values())
k = list(d.keys())
sudo = []
for i in d:
sudo.append([d[i], i])
sudo.sort()
m = max(sudo)[0]
for j in sudo:
if j[0] == m:
return [j[1], m]
for _ in [0] * int(input()):
n, x = map(int, input().split())
arr = [int(a) for a in input().split()]
dic = {}
for i in arr:
if i % x not in dic:
dic[i % x] = 1
else:
dic[i % x] += 1
if 0 in dic:
dic[0] = 0
k, m = keywithmaxval(dic)
if k != 0:
print((m - 1) * x + (x - k + 1))
else:
print(0)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR RETURN LIST VAR NUMBER VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
T = int(input())
for _ in range(T):
n, k = map(int, input().strip().split())
a_list = map(int, input().strip().split())
divisors = {}
_mode = 0
for a in a_list:
div = a % k
if div == 0:
continue
elif div in divisors:
divisors[div] += 1
else:
divisors[div] = 1
_mode = max(divisors[div], _mode)
min_d = k
for d, count in divisors.items():
if count == _mode:
min_d = min(min_d, d)
if _mode == 0:
print(0)
else:
print(k * (_mode - 1) + (k - min_d) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
d = {}
l = list(map(int, input().split()))
for i in l:
if i % k in d:
d[i % k] += 1
else:
d[i % k] = 1
maxx = 0
for i in l:
c = 0
c = d[i % k]
if i % k != 0:
maxx = max(maxx, c * k - i % k)
if maxx:
print(maxx + 1)
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = [int(_) for _ in input().split()]
A = [(int(_) % k) for _ in input().split()]
D = dict()
m = 0
for _ in range(n):
if A[_] != 0:
if A[_] in D:
D[A[_]] += 1
else:
D[A[_]] = 1
m = max(m, D[A[_]])
if D == dict():
print(0)
else:
for _ in sorted(D):
if m == D[_]:
print(k * (m - 1) + k - _ + 1)
break
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
def all_same(lineup):
return all([(x == 0) for x in lineup])
for i in range(int(sys.stdin.readline())):
size, divisible = [int(x) for x in sys.stdin.readline().split()]
lineup = sorted([(int(x) % divisible) for x in sys.stdin.readline().split()])
d = {}
for i in range(size):
if lineup[i] in d:
d[lineup[i]] += 1
else:
d[lineup[i]] = 1
highest = -1
if all_same(lineup):
print("0")
continue
for i in d:
if i == 0:
d[i] = 0
if highest < d[i]:
highest = d[i]
check = i
print(divisible * (highest - 1) + divisible - check + 1)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = {}
for i in range(n):
q = k - a[i] % k
if q in b:
b[q] += 1
else:
b[q] = 1
ans = 0
for i in b:
if i != k:
ans = max(ans, i + b[i] * k - k)
print(ans + (ans != 0))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t:
inp1 = list(map(int, input().strip().split()))[:2]
n, k = inp1[0], inp1[1]
arr = list(map(int, input().strip().split()))[:n]
dict1 = {}
for i in arr:
rem = i % k
if rem:
if k - rem in dict1:
dict1[k - rem] += 1
else:
dict1[k - rem] = 1
max1 = 0
for i in dict1:
max1 = max(max1, dict1[i])
max2 = 0
for i in dict1:
if dict1[i] == max1:
max2 = max(max2, i)
ans = (max1 - 1) * k + max2 + 1
if ans <= 0:
print(0)
else:
print(ans)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solve(n, k, a):
ost = [(k - i % k) for i in a]
if ost == [k] * n:
print(0)
else:
d = {}
x = -1
maxT = -1
for i in ost:
if i == k:
continue
if d.get(i, -1) == -1:
d[i] = 1
else:
d[i] += 1
if d[i] > maxT:
x = i
maxT = d[i]
elif d[i] == maxT:
x = max(i, x)
print(x + k * (maxT - 1) + 1)
t = int(input())
while t:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
solve(n, k, a)
t -= 1
|
FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
from sys import stdin
def input():
return next(stdin)
def main():
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
tab = input().split()
for p in range(n):
tab[p] = int(tab[p])
tab[p] = k - tab[p] % k
tab = sorted(tab)
x = 0
if tab[0] == k:
print(0)
elif n == 1:
print(tab[0] + 1)
else:
x = tab[0]
com = 0
sup = 0
num = 0
for i in range(1, n):
if tab[i] == k:
break
elif tab[i] == tab[i - 1]:
com += 1
if com > sup:
sup = com
num = tab[i]
elif com == sup:
num = tab[i]
else:
com = 0
if sup == 0:
if tab[i] == k:
print(tab[i - 1] + 1)
else:
print(tab[i] + 1)
else:
print(num + 1 + sup * k)
main()
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = [int(_) for _ in input().split()]
d = {}
for i in a:
num = (k - i % k) % k
if num == 0:
continue
if num in d:
d[num] += 1
else:
d.setdefault(num, 1)
max_key, max_value = 0, 0
for i in d.items():
if i[1] == max_value:
if max_key < i[0]:
max_key = i[0]
elif i[1] > max_value:
max_key = i[0]
max_value = i[1]
if max_key == 0:
print(0)
else:
print(max_key + k * (max_value - 1) + 1)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def task_D():
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
array = list(map(int, input().split()))
dict_ostatkov = {}
sum_ostatkov = 0
for curr in array:
ostatok = curr % k
if ostatok != 0:
sum_ostatkov += ostatok
if ostatok not in dict_ostatkov:
dict_ostatkov[ostatok] = 1
else:
dict_ostatkov[ostatok] += 1
if sum_ostatkov == 0:
print(0)
else:
count_max_ostatok = max(dict_ostatkov.values())
max_ostatok = min(
[
key
for key in dict_ostatkov.keys()
if dict_ostatkov[key] == count_max_ostatok
]
)
print(k * count_max_ostatok - max_ostatok + 1)
def main():
task_D()
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def sol4():
for t in range(int(input())):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
a1 = []
for i in a:
if i % k != 0:
a1.append(k - i % k)
if len(a1) == 0:
print(0)
continue
a1.sort()
ans = a1[0]
curr = a1[0]
for i in range(1, len(a1)):
if a1[i] != a1[i - 1]:
curr = a1[i]
else:
curr += k
ans = max(ans, curr)
print(ans + 1)
sol4()
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t > 0:
n, k = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
for i in range(n):
arr[i] = arr[i] % k
dic = {}
for i in range(n):
if arr[i] in dic:
dic[arr[i]] += 1
else:
dic[arr[i]] = 1
maxi = 0
count = 0
for j in dic.keys():
if dic[j] > count and j != 0:
maxi = j
count = dic[j]
elif dic[j] == count and j < maxi and j != 0:
maxi = j
count = dic[j]
if count == 0:
print(0)
else:
print(k * (count - 1) + k - maxi + 1)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
addA = []
for elem in a:
if elem % k == 0:
continue
else:
addA.append(k - elem % k)
maxAddition = 0
addA.sort()
count = 0
lastelem = -1
for elem in addA:
if lastelem == -1:
lastelem = elem
count = 1
elif elem != lastelem:
if maxAddition < (count - 1) * k + lastelem + 1:
maxAddition = (count - 1) * k + lastelem + 1
count = 1
lastelem = elem
else:
count += 1
if maxAddition < (count - 1) * k + lastelem + 1:
maxAddition = (count - 1) * k + lastelem + 1
print(maxAddition)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
T = int(input())
while T > 0:
T -= 1
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = {}
for i in range(N):
A[i] %= K
A[i] = (K - A[i]) % K
if A[i] > 0:
if A[i] in D:
D[A[i]] += 1
else:
D[A[i]] = 1
c = 0
j = 0
for x, y in D.items():
if y > c:
c = y
j = x
elif y == c:
if j < x:
j = x
ans = max(0, j + K * (c - 1) + 1)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
needs = []
found = {}
d = 0
for v in a:
s = k - v % k
b = s if v % k != 0 else 0
if b == 0:
d += 1
if b not in found and b != 0:
found[b] = 1
elif b != 0:
found[b] += 1
b += k * (found[b] - 1)
needs.append(b)
if d != n:
print(max(needs) + 1)
else:
print(0)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for i in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
x = 0
a = list(map(lambda x: (k - x % k) * (x % k != 0), a))
a.sort()
c = 1
d = a.copy()
for j in range(n):
if a[j] != 0:
if j == 0:
x = a[j]
elif a[j] == a[j - 1]:
d[j] = c * k + a[j]
c = c + 1
else:
c = 1
print(max(d) + 1 * (max(d) != 0))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t:
m = f = 0
n, k = map(int, input().split(" "))
l = list(map(int, input().split(" ")))
for i in range(n):
if l[i] % k == 0:
l[i] = 0
else:
l[i] = k - l[i] % k
l.sort()
for i in range(n):
if i > 0 and l[i] == l[i - 1] and l[i] > 0:
g += 1
else:
g = 1
if g > m or g == m and l[i] > f:
m = g
f = l[i]
if f == 0:
print(0)
else:
print((m - 1) * k + f + 1)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
a[i] = a[i] % k
a.sort()
if sum(a) == 0:
print("0")
else:
maximum = 0
number = -1
if a[0] == 0:
temp = 0
else:
temp = 1
for i in range(1, n):
if a[i] == a[i - 1] and a[i] != 0:
temp += 1
elif a[i] != a[i - 1]:
if maximum < temp:
maximum = temp
number = a[i - 1]
temp = 1
if maximum < temp:
maximum = temp
number = a[n - 1]
print(k * maximum - number + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for q in range(t):
n, k = map(int, input().split())
l = list(map(int, input().split()))
d = {}
maxi = 0
val = 0
for i in range(len(l)):
x = k - l[i] % k
if x != k and x in d:
d[x] += k
if maxi < d[x]:
maxi = d[x]
elif x != k:
d[x] = x
if maxi < d[x]:
maxi = d[x]
if maxi == 0:
print(0)
else:
print(maxi + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solution(arr, k):
r = [(i % k) for i in arr]
d = {}
for i in r:
d[i] = d.get(i, 0) + 1
e = []
for i in d:
if i > 0:
e.append(d[i])
if len(e) == 0:
return 0
val = max(e)
f = []
for i in d:
if d[i] == val and i > 0:
f.append(i)
return val * k - min(f) + 1
for _ in range(int(input())):
n, k = map(int, input().split())
arr = [int(x) for x in input().split()]
print(solution(arr, k))
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(n):
r = a[i] % k
if r != 0:
if r in d:
d[r].append(d[r][-1] + k)
else:
d[r] = [k - r]
x = 0
for i in d:
x = max(max(d[i]), x)
if d:
print(x + 1)
else:
print(0)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR LIST BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = dict()
for i in map(lambda x: k - int(x) % k, input().split()):
if i == k:
continue
if a.get(i, -1) == -1:
a[i] = 1
else:
a[i] += 1
maxv = 0
maxi = 0
for i in sorted(a.keys()):
if a[i] >= maxv:
maxv = a[i]
maxi = i
print(max(k * maxv + (maxi + 1) % k + (((maxi + 1) % k == 0) - 1) * k, 0))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
a = input()
for x in range(int(a)):
b = input().split(" ")
c = input().split(" ")
dict1 = {}
for i in c:
if int(i) % int(b[1]) != 0:
tag = int(b[1]) - int(i) % int(b[1])
if tag not in dict1:
dict1[tag] = 1
else:
dict1[tag] += 1
ans = 0
if len(dict1) == 0:
print(ans)
else:
for i in dict1:
if dict1[i] == 1:
ans = max(i, ans)
else:
tag = int(b[1]) * (dict1[i] - 1) + i
ans = max(tag, ans)
print(ans + 1)
|
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
dic = {}
c = 1
for j in a:
temp = k - j % k
if temp == k:
continue
if temp in dic:
dic[temp] += 1
else:
dic[temp] = 1
for j in dic.keys():
if (dic[j] - 1) * k + j + 1 > c:
c = (dic[j] - 1) * k + j + 1
if dic == {}:
print("0")
else:
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR DICT EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
xval = []
d = {}
for i in range(n):
if k - a[i] % k not in d.keys():
d[k - a[i] % k] = 1
else:
d[k - a[i] % k] += 1
if a[i] % k != 0:
temp = d[k - a[i] % k] * k - a[i] % k
xval.append(temp)
else:
xval.append(0)
xval.sort()
req = 0
if sum(xval) != 0:
print(xval[-1] + 1)
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
z = int(input())
for h in range(z):
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = []
for i in range(n):
if a[i] < k:
m.append(k - a[i])
elif a[i] > k and a[i] % k != 0:
m.append(k - a[i] % k)
else:
m.append(a[i] % k)
m.sort()
ans = [m[0]]
for i in range(1, n):
if m[i] == m[i - 1] and m[i] != 0:
ans.append(ans[i - 1] + k)
else:
ans.append(m[i])
if sum(m) == 0:
print(0)
else:
print(max(ans) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def zra(arr, n, k):
hm = dict()
for i in range(n):
m = arr[i] % k
if m != 0:
if m in hm:
hm[m] += 1
else:
hm[m] = 1
if len(hm) == 0:
return "0"
else:
l = []
for i in hm:
n = k - i
n1 = k * (hm[i] - 1) + n
l.append(n1)
return max(l) + 1
t = int(input())
for _ in range(t):
n, k = input().split()
n = int(n)
k = int(k)
arr = list(map(int, input().split()))
print(zra(arr, n, k))
print("")
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t:
n, k = map(int, input().split())
a = list(map(int, input().split()))
max = 0
curr = 0
d1 = {}
for i in a:
temp = i % k
if temp != 0:
if k - temp in d1.keys():
d1[k - temp] += 1
if d1[k - temp] > max:
curr = k - temp
max = d1[k - temp]
elif d1[k - temp] == max:
if k - temp > curr:
curr = k - temp
max = d1[k - temp]
else:
d1[k - temp] = 1
if d1[k - temp] > max:
curr = k - temp
max = d1[k - temp]
elif d1[k - temp] == max:
if k - temp > curr:
curr = k - temp
max = d1[k - temp]
if max == 0:
print(0)
else:
print((max - 1) * k + curr + 1)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = (int(var) for var in input().split())
arr = [int(var) for var in input().split()]
remainder = {}
maxMoves = -1
for num in arr:
rem = num % k
if rem != 0:
remainder[rem] = remainder.get(rem, 0) + 1
for rem in remainder:
cnt = remainder[rem]
reqd = k - rem
maxMoves = max(maxMoves, reqd + (cnt - 1) * k)
print(maxMoves + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
tst = int(input())
for ts in range(tst):
n, k = map(int, input().split())
a = [((k - int(i) % k) % k) for i in input().split()]
b = {i: (0) for i in a}
for i in a:
b[i] += 1
m, mi = 1, -1
for i in sorted(b.keys()):
if i != 0 and b[i] >= m:
m, mi = b[i], i
if mi == -1:
print(0)
else:
print(k * (b[mi] - 1) + mi + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = [int(i) for i in input().split()]
a = [((k - int(i) % k) % k) for i in input().split() if (k - int(i) % k) % k != 0]
d = {}
for i in a:
if d.get(i) == None:
d[i] = 1
else:
d[i] += 1
if len(a) == 0:
print(0)
else:
m = a[0]
for key in d:
if d[key] > d[m] or d[key] == d[m] and key > m:
m = key
print((d[m] - 1) * k + m + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
(*li,) = map(int, input().split())
dict1 = {}
key, cnt = 0, 0
for i in range(n):
if li[i] % k:
req = k - li[i] % k
dict1[req] = dict1.get(req, 0) + 1
if cnt < dict1[req]:
cnt = max(cnt, dict1[req])
for u, v in dict1.items():
if v == cnt:
key = max(key, u)
print(max(k * (cnt - 1) + key + 1, 0))
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
arr = []
for j in range(n):
r = a[j] % k
if r == 0:
arr.append(0)
else:
arr.append(k - r)
j = 0
x = 0
count = 0
sme = 0
arr.sort()
while j < len(arr) and arr[j] == 0:
j += 1
while j < len(arr):
if j < len(arr) and x < arr[j]:
x = arr[j]
while j < len(arr) and x == arr[j]:
sme += 1
j += 1
if sme != 0:
max_x = x + 1 + (sme - 1) * k
x += 1
if max_x > count:
count = max_x
sme = 0
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def answer(n, k, A):
d = {}
maxi = 0
index = 0
for i in range(n):
key = k - A[i] % k
if key != k:
if key in d:
d[key] += 1
if d[key] > maxi:
maxi = d[key]
index = key
elif d[key] == maxi and key > index:
index = key
else:
d[key] = 1
if d[key] > maxi:
maxi = d[key]
index = key
elif d[key] == maxi and key > index:
index = key
if maxi == 0:
return 0
return (maxi - 1) * k + index + 1
t = int(input())
for i in range(t):
n, k = map(int, input().split())
A = list(map(int, input().split()))
print(answer(n, k, A))
|
FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
c = 0
for i in range(n):
x = k - a[i] % k
if k == x:
c += 1
elif d.get(x) == None:
d[x] = 1
else:
d[x] += 1
if c == n:
print(0)
continue
l = d.keys()
ma = 0
p = 0
res = 0
for i in l:
if ma <= d[i]:
ma = d[i]
p = i
res = max(res, (ma - 1) * k + 1 + p)
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
ans = []
for i in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
b = [(k - x % k) for x in a if x % k != 0]
if not b:
ans.append(0)
else:
for el in b:
d[el] = d.get(el, 0) + 1
arr = []
for el in d:
arr.append(el + k * (d[el] - 1))
ans.append(max(arr) + 1)
for el in ans:
print(el)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
data = map(int, input().split())
abcd = dict()
for j in data:
r = j % k
if r in abcd:
abcd[r] += 1
else:
abcd[r] = 1
finalist = list()
for j in abcd:
if j == 0:
finalist.append(0)
else:
finalist.append(k - j + (abcd[j] - 1) * k)
if max(finalist) == 0:
print(0)
else:
print(max(finalist) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
mp = {(i % k): (0) for i in arr}
ans = 0
for i in range(n):
if arr[i] % k:
mp[arr[i] % k] += 1
ans = max(mp[i] * k - i for i in mp.keys())
if ans:
ans += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
t = 1
t = int(input())
for i in range(t):
n, k = list(map(int, sys.stdin.readline().strip().split()))
a = list(map(int, sys.stdin.readline().strip().split()))
x = []
for j in a:
x.append((k - (j - k * (j // k))) % k)
x.sort()
if x[-1] == 0:
print(0)
continue
j = 1
while j < n:
if x[j] == 0:
j += 1
continue
xxx = k
z = j
while z < n and x[j - 1] == x[z]:
x[z] += xxx
z += 1
xxx += k
if z == j:
j += 1
else:
j = z
print(max(x) + 1)
|
IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for t in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(n):
arr[i] = (k - arr[i] % k) % k
arr.sort()
i = 0
while i < n:
if arr[i] > 0:
j = i + 1
while j < n and arr[i] == arr[j]:
arr[j] = arr[i] + (j - i) * k
j += 1
i = j
else:
i += 1
if max(arr) == 0:
print(0)
else:
print(max(arr) + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a2 = sorted([(a[i] % k) for i in range(n) if a[i] % k != 0])
dct = {}
for i in a2:
if dct.get(i, False):
dct[i] = dct[i] + 1
else:
dct[i] = 1
ans = 0
for key in dct:
ans = max(ans, dct[key] * k - key + 1)
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for x in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
mod = []
for i in l:
if i % k == 0:
mod += [0]
else:
mod += [k - i % k]
mod.sort()
cnt = 1
mod1 = [mod[0]]
for i in range(1, n):
if mod[i] == mod[i - 1] and mod[i] != 0:
cnt += 1
else:
cnt = 1
mod1 += [mod[i] + (cnt - 1) * k]
mod1.sort()
ans = mod1[0]
for i in range(1, n):
ans += mod1[i] - mod1[i - 1]
if ans != 0:
ans += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR LIST NUMBER VAR LIST BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR LIST BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _t in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
a[i] = a[i] % k
s = {}
for i in a:
if i == 0:
continue
v = k - i
if v not in s:
s[v] = 1
else:
x = v + k * s[v]
s[v] += 1
s[x] = 1
if s:
print(max(s) + 1)
else:
print(0)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solve():
n, k = map(int, input().split())
l = list(map(int, input().split()))
d = {}
for e in l:
if e % k != 0:
if e % k in d:
d[e % k] += 1
else:
d[e % k] = 1
vals = d.values()
if len(vals) == 0:
return 0
Max = max(vals)
Min = k
for key, val in d.items():
if val == Max and key < Min:
Min = key
return (Max - 1) * k + (k - Min + 1)
t = int(input())
for i in range(t):
ans = solve()
print(ans)
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for aa in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans, mp = 0, {}
for i in range(n):
cha = k - a[i] % k
if cha not in mp.keys():
mp[cha] = 1
else:
mp[cha] += 1
for key in mp.keys():
if key == k:
continue
if (mp[key] - 1) * k + key > ans:
ans = (mp[key] - 1) * k + key
if ans:
print(ans + 1)
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def main():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
d, mx, ans = {}, 0, 0
for i in range(n):
if arr[i] % k:
x = k - arr[i] % k
if d.get(x):
d[x] += 1
else:
d[x] = 1
mx = max(mx, d[x])
for key, value in d.items():
if value == mx:
ans = max(ans, k * (value - 1) + key + 1)
print(ans)
for _ in range(int(input())):
main()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
dec = []
for a in arr:
rem = a % k
if rem != 0:
dec.append(k - rem)
dec.sort()
ans = 0
i = 0
dn = len(dec)
if dn != 0:
ans = 1
while i < dn:
cur = dec[i]
rep = 0
while i < dn and cur == dec[i]:
rep += 1
i += 1
ans = max((rep - 1) * k + cur, ans)
if dn != 0:
ans += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = [int(p) for p in input().split()]
arr = [int(p) for p in input().split()]
for i in range(len(arr)):
arr[i] = arr[i] % k
arr.sort()
i = 0
j = 0
while j < len(arr):
temp = arr[i]
if temp == 0:
i += 1
j += 1
continue
while temp == arr[j] and j < len(arr):
arr[j] = k - arr[j] + k * (j - i)
j += 1
if j >= len(arr):
break
i = j
if max(arr):
print(max(arr) + 1)
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
while t > 0:
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
rems = {}
for x in nums:
r = x % k
if r > 0:
r = k - r
rems[r] = rems.get(r, 0) + 1
maxr = 0
maxi = 0
rs = sorted(list(rems.keys()))
for x in rs:
r = rems[x]
if r >= maxr:
maxr = r
maxi = x
moves = 0
if maxr > 0:
moves = k * maxr - (k - maxi - 1)
print(moves)
t = t - 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
line = input()
t = int(line)
for j in range(t):
line = input()
n, k = [int(i) for i in line.split(" ")]
line = input()
nums = [int(i) for i in line.split(" ")]
memo = {}
for i in nums:
memo[i % k] = memo.get(i % k, 0) + 1
r, last = 0, 0
for i, v in memo.items():
if i == 0:
continue
if v > r:
r = memo[i]
last = i
elif v == r:
last = min(i, last)
if r == 0:
print(0)
else:
print(r * k - last + 1)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
o = []
for i in a:
if i % k != 0:
o.append(k - i % k)
if len(o) == 0:
print(0)
continue
o.sort()
i = 0
j = 0
mv = o[0]
mt = 0
while j < len(o):
if o[j] != o[i]:
if mt <= j - i:
mv = o[i]
mt = j - i
i = j
j += 1
else:
j += 1
if mt <= j - i:
mv = o[i]
mt = j - i
print((mt - 1) * k + 1 + mv)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solve(n, k, a):
rem = {}
for x in a:
d = x % k
if d != 0:
rem[d] = rem.get(d, 0) + 1
sol = 0
for d, f in rem.items():
c = f * k - d
sol = max(sol, c)
return sol + int(sol > 0)
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(solve(n, k, a))
|
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
input = sys.stdin.readline
inp, ip = lambda: int(input()), lambda: [int(w) for w in input().split()]
for _ in range(inp()):
n, k = ip()
x = ip()
d = []
for i in range(n):
t = x[i] % k
if t:
d.append(k - t)
if d == []:
print(0)
continue
dt = {}
for i in d:
dt[i] = dt.get(i, 0) + 1
vis = {}
for j in sorted(dt):
i = j
for ii in range(dt[j]):
flag = 0
while not vis.get(i, 1):
i += k
vis[i] = 0
i += k
print(max(vis) + 1)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
A = list(map(int, input().split()))
count = {}
for i in range(n):
A[i] %= k
for i in range(n):
if A[i] == 0:
continue
t = k - A[i]
if t in count:
count[t] += 1
else:
count[t] = 1
ans = 0
for c in count:
ans = max(ans, c + (count[c] - 1) * k + 1)
print(ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def strip_(arr, k):
arr_copy = []
for i in arr:
if i != 0:
arr_copy.append(k - i)
return arr_copy
t = int(input())
for i in range(t):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
for j in range(len(arr)):
arr[j] = arr[j] % k
arr = strip_(arr, k)
arr.sort()
ans = 0
if not arr:
print(0)
else:
ans += 1
prev = None
coeff = 0
for j in range(len(arr)):
if arr[j] == prev:
coeff += 1
else:
coeff = 0
if prev is None:
prev = 1
ans = max(ans, coeff * k + arr[j])
prev = arr[j]
print(ans + 1)
|
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
mk = [((k - a[i] % k) % k) for i in range(n)]
mk.sort()
mknodup = [mk[0]]
nindx = 0
for i in range(1, n):
if mk[i] == 0:
mknodup.append(0)
elif mk[i] == mk[nindx]:
mknodup.append(mk[i] + (i - nindx) * k)
else:
mknodup.append(mk[i])
nindx = i
mx = max(mknodup)
if mx == 0:
print(0)
else:
print(mx + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
n, k = [int(x) for x in input().split()]
arr = [
((int(y) // k + 1) * k - int(y) if int(y) % k else 0) for y in input().split()
]
arr = sorted(arr)
max_move, k_now, i = 0, 0, 0
while i < n:
j = i
adnd = 0
if j < n - 1 and arr[j] != arr[j + 1]:
if max_move < adnd + arr[j + 1]:
max_move = adnd + arr[j + 1]
else:
while j < n - 1 and arr[j] == arr[j + 1] and arr[j] != 0:
adnd += k
if max_move < adnd + arr[j + 1]:
max_move = adnd + arr[j + 1]
j += 1
i = j + 1
if len(arr) == 1:
max_move = arr[0]
print(max_move + 1 if max_move else max_move)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
class Solution:
def __init__(self):
self.n, self.k = [int(x) for x in input().split()]
self.a = [int(x) for x in input().split()]
def solve_and_print(self):
k, x = self.k, 0
liste = sorted((k - ai % k) % k for ai in self.a if ai % k)
last = multiple = 0
n = len(liste)
for i in range(1, n):
if liste[i] == liste[i - 1]:
multiple += 1
else:
last = max(last, liste[i - 1] + multiple * k)
multiple = 0
if n:
last = max(last, liste[n - 1] + multiple * k)
if last:
last += 1
print(last)
for _ in range(int(input())):
Solution().solve_and_print()
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
tests = int(input())
for _ in range(tests):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
max1 = 0
d1 = {}
c = 0
for i in range(n):
v = k - arr[i] % k
if arr[i] % k == 0:
continue
z = v - 1
if z not in d1:
d1[z] = 1
else:
v += k * d1[v - 1]
d1[z] += 1
if v > max1:
max1 = v
if max1 == 0:
print(0)
else:
print(max1 + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for m in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
vd = 0
d = dict()
rem = list()
for i in range(n):
vd = k - a[i] % k
if vd not in d.keys():
d[vd] = 1
else:
d[vd] += 1
if a[i] % k != 0:
rem.append(vd + (d[vd] - 1) * k)
else:
rem.append(0)
ans = max(rem)
if ans == 0:
print(ans)
else:
print(ans + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for q in range(t):
n, k = list(map(int, input().split(" ")))
ent = list(map(int, input().split(" ")))
resto = [0] * n
cont = 0
for i in range(n):
c = k - ent[i] % k
if c == k:
resto[i] = 0
else:
resto[i] = k - ent[i] % k
if resto[i] != 0:
cont = 1
if cont == 0:
print(0)
else:
resto.sort()
r = list(reversed(resto))
m = r[0]
cont = 1
for j in range(0, n):
if j != 0 and r[j] != 0:
if r[j] == r[j - 1]:
cont += 1
m = max(m, r[j] + (cont - 1) * k)
else:
cont = 1
m = max(m, r[j] + (cont - 1) * k)
print(m + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
x = 0
undivCnt = 0
maxUndiv = 0
l = []
d = {}
res = 0
for i in range(n):
if a[i] % k != 0:
undivCnt += 1
need = a[i] // k * k + k - a[i]
if need in d:
d[need] += 1
else:
d[need] = 1
for key, val in d.items():
if val > 1:
d[key] = key + k * (val - 1)
else:
d[key] = key
res = max(res, d[key])
if d:
print(res + 1)
else:
print(0)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solve():
n, k = map(int, input().split(" "))
l = list(map(int, input().split(" ")))
dic = {}
for e in l:
if e % k == 0:
continue
key = k - e % k
if key in dic.keys():
dic[key] += 1
else:
dic[key] = 1
ele = list(dic.keys())
if len(ele) == 0:
print(0)
return
Mkey = ele[0]
Mval = dic[ele[0]]
for e in ele:
if dic[e] > Mval:
Mval = dic[e]
Mkey = e
res = 0
for e in ele:
if dic[e] == Mval:
res = max(res, k * (dic[e] - 1) + e + 1)
print(res)
t = int(input())
while t:
solve()
t -= 1
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for testcase in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
print(0)
continue
if n == 1:
print((k - a[0] % k) % k + 1)
continue
a = filter(lambda i: i != 0, sorted(list((k - i % k) % k for i in a), reverse=True))
v, id = 0, -1
prev = -1
cnt = 0
for i in a:
if i == prev:
cnt += 1
else:
v, id = max((v, id), (cnt, prev))
cnt = 1
prev = i
v, id = max((v, id), (cnt, prev))
if id == -1:
print(0)
else:
print((v - 1) * k + id + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for i in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = 0
d = {}
for i in a:
if i % k not in d:
d[i % k] = 1
else:
d[i % k] += 1
for key in d:
if key != 0:
m = max(m, d[key] * k - key)
if m != 0:
m += 1
print(m)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for i in range(t):
max_value = 0
zero_ans = True
n, k = map(int, input().split(" "))
nums = list(map(int, input().split(" ")))
a = dict()
for x in nums:
if x % k != 0:
x = k - x % k
if not x in a.keys():
a[x] = x
else:
a[x] += k
x = a[x]
max_value = max(max_value, x)
zero_ans = False
if zero_ans:
print(0)
else:
print(max_value + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for t in range(int(input())):
n, k = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
arr = []
for i in a:
if i % k != 0:
arr.append(k - i % k)
if arr == []:
print(0)
continue
dic = {}
for i in arr:
if i in dic.keys():
dic[i] += 1
else:
dic[i] = 1
array = []
for i in dic.keys():
array.append([dic[i], i])
array.sort(key=lambda x: (x[0], x[1]))
ans = (array[-1][0] - 1) * k
ans += array[-1][1] + 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
input_length = int(input())
while input_length != 0:
nk_string = str(input())
n, k = tuple(nk_string.split())
n, k = int(n), int(k)
array_now_string = str(input())
input_length -= 1
array_now = array_now_string.split()
array_now = [int(x) for x in array_now]
remainder_array = [((x // k + 1) * k - x if x % k != 0 else 0) for x in array_now]
remainder_array = sorted(remainder_array)
temp, iter1, count = 0, 0, 0
for i in range(0, len(remainder_array)):
if remainder_array[i] == 0:
continue
if remainder_array[i] == temp:
iter1 += 1
remainder_array[i] += iter1 * k
elif remainder_array[i] != temp:
temp = remainder_array[i]
iter1 = 0
last_value = 0
x = 0
remainder_array = sorted(remainder_array)
for new_value in remainder_array:
if new_value != 0 and x == 0:
count += 1
x += 1
count += new_value - last_value
last_value = new_value
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for _ in range(int(input())):
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
ar = []
f = 0
for i in l:
if i % k != 0:
f = 1
ar.append(k - i % k)
if f == 0:
print(0)
continue
d = {}
for i in ar:
if i in d:
d[i] += 1
else:
d[i] = 1
m = 0
for i in sorted(d):
if d[i] >= m:
m = d[i]
ans = i
print(k * (m - 1) + ans + 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
def solve(n, divisor, arr):
remainderArr = [(x % divisor) for x in arr]
remainderArr.sort()
ans = 0
start = 0
for index in range(1, n):
if remainderArr[index] == remainderArr[start]:
continue
else:
if remainderArr[start] != 0:
number = index - start
required = divisor - remainderArr[start]
total = divisor * (number - 1)
total += required + 1
if total > ans:
ans = total
start = index
if remainderArr[start] != 0:
number = n - start
required = divisor - remainderArr[start]
total = divisor * (number - 1)
total += required + 1
if total > ans:
ans = total
return ans
for _ in range(int(input())):
n, d = list(map(int, input().split()))
arr = list(map(int, input().split()))
print(solve(n, d, arr))
|
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
for t in range(int(input())):
n, k = map(int, input().split(" "))
ar = list(map(lambda x: int(x) % k, input().split(" ")))
r = 0
count = 0
ar.sort()
ar = [0] + ar
for i in range(n + 1):
if ar[i] != 0:
if ar[i] != ar[i - 1]:
count = max(count, r)
r = k - ar[i]
else:
r += k
count = max(count, r)
if count == 0:
print(0)
else:
print(1 + count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
from sys import maxsize, stdin, stdout
def solve():
pass
test = 1
test = int(input())
for t in range(0, test):
n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
s = {}
b = [0] * n
ans = -maxsize
for i in range(n):
el = (k - a[i] % k) % k
if el in s and el != 0:
s[el] += 1
el = el + (s[el] - 1) * k
elif el != 0:
s[el] = 1
ans = max(ans, el)
if ans != 0:
print(ans + 1)
else:
print(0)
ans = solve()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
A = list(map(int, input().split()))
diff = {}
for a in A:
if not k - a % k in diff:
diff[k - a % k] = 1
else:
diff[k - a % k] += 1
res = 0
ma = 0
for i, v in diff.items():
if i != k:
ma = max(v * k + i, ma)
res = ma - (k - 1)
print(max(res, 0))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(n):
c = (k - a[i] % k) % k
b.append(c)
c = {}
for i in range(len(b)):
if b[i] != 0:
if b[i] in c.keys():
c[b[i]] += 1
else:
c[b[i]] = 1
s = []
for i in c:
s.append(k * (c[i] - 1) + i)
if len(s) == 0:
print(0)
else:
print(max(s) + 1)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
You are given an array $a$ consisting of $n$ positive integers.
Initially, you have an integer $x = 0$. During one move, you can do one of the following two operations: Choose exactly one $i$ from $1$ to $n$ and increase $a_i$ by $x$ ($a_i := a_i + x$), then increase $x$ by $1$ ($x := x + 1$). Just increase $x$ by $1$ ($x := x + 1$).
The first operation can be applied no more than once to each $i$ from $1$ to $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$ (the value $k$ is given).
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) β the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5; 1 \le k \le 10^9$) β the length of $a$ and the required divisior. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer β the minimum number of moves required to obtain such an array that each its element is divisible by $k$.
-----Example-----
Input
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8
Output
6
18
0
227
8
-----Note-----
Consider the first test case of the example: $x=0$, $a = [1, 2, 1, 3]$. Just increase $x$; $x=1$, $a = [1, 2, 1, 3]$. Add $x$ to the second element and increase $x$; $x=2$, $a = [1, 3, 1, 3]$. Add $x$ to the third element and increase $x$; $x=3$, $a = [1, 3, 3, 3]$. Add $x$ to the fourth element and increase $x$; $x=4$, $a = [1, 3, 3, 6]$. Just increase $x$; $x=5$, $a = [1, 3, 3, 6]$. Add $x$ to the first element and increase $x$; $x=6$, $a = [6, 3, 3, 6]$. We obtained the required array.
Note that you can't add $x$ to the same element more than once.
|
q = int(input())
for Q in range(q):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
a[i] = (k - a[i] % k) % k
a.sort()
for i in range(1, n):
if a[i] == 0:
continue
if a[i] % k == a[i - 1] % k:
a[i] = a[i - 1] + k
res = max(a)
if res == 0:
print(0)
else:
print(res + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.