Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Morty has an array A of length N and an integer K ,He wants to make the sum of the elements of the array divisible
Morty has an array A of length N and an integer K ,He wants to make the sum of the elements of the array divisible by K, by doing the following operation any number of times (possibly zero) :-
- Choose any element of the current array and replace it by any positive integer.
He needs your help to know the minimum number of operations he needs to perform to achieve this.
Input Format
the first line N : length of the array and K
the second line the elements of the array A[0],A[1],...,A[N]
Constraints
1N100 1K10^5 1A[i]10^5
Output Format
The minimum required number of operations.
Sample Input 0
3 2
1 1 1
Sample Output 0
1
Explanation 0
Initially the sum = 1+1+1 = 3 , and 3 is not divisible by 2 .
so if we change A[0]=4 (for example) the sum now = 4+1+1 = 6 , and 6 is divisible by 2 . so we need one operation to make the sum divisible by 2.
Sample Input 1
3 3
1 1 1
Sample Output 1
0
Explanation 1
the sum = 1+1+1 = 3 which is divisible by 3 so no operations are required.
Sample Input 2
5 5
1 2 3 4 5
Sample Output 2
0
Explanation 2
the sum = 1+2+3+4+5 = 15 which is divisible by 5.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started