Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed
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.
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 Aloj ATLAN Constraints 15N5100 sksto5 13AS1045 Output Format the minimum required number of operations Sample input STA yerere se TE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What is the difference between a plan and a budget?

Answered: 1 week ago

Question

2. Should a disciplinary system be established at Carter Cleaning?

Answered: 1 week ago

Question

=+associated with political parties and if so, which ones? Are

Answered: 1 week ago