Knowee
Questions
Features
Study Tools

You are given an array of integers of size N and another integer K. Find the size of the largest subset of the array in which the sum of any two numbers is not perfectly divisible by K.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the size of the array and K, separated by a space. The second line contains the elements of the array.Output FormatFor each test case, print the size of the largest subset in which the sum of any two numbers is not perfectly divisible by K, separated by a newline.Constraints10 points1 <= T <= 1001 <= N <= 101 <= K <= 500 <= arr[i] <= 10220 points1 <= T <= 1001 <= N <= 1021 <= K <= 1020 <= arr[i] <= 10570 points1 <= T <= 1001 <= N <= 1041 <= K <= 1050 <= arr[i] <= 105ExampleInput24 31 7 2 4 5 21 2 3 4 5Output32ExplanationTest Case 1:The subset {1, 7, 4} is the largest subset with the sum of any two numbers { {1,7}=8, {1,4}=5, {7,4}=11 } not perfectly divisible by K=3.Test Case 2:The subset {1, 2} or {2, 3} or {3, 4} or {4, 5} can be the largest subset with the sum of any two numbers not perfectly divisible by K=2.

Question

You are given an array of integers of size N and another integer K. Find the size of the largest subset of the array in which the sum of any two numbers is not perfectly divisible by K.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the size of the array and K, separated by a space. The second line contains the elements of the array.Output FormatFor each test case, print the size of the largest subset in which the sum of any two numbers is not perfectly divisible by K, separated by a newline.Constraints10 points1 <= T <= 1001 <= N <= 101 <= K <= 500 <= arr[i] <= 10220 points1 <= T <= 1001 <= N <= 1021 <= K <= 1020 <= arr[i] <= 10570 points1 <= T <= 1001 <= N <= 1041 <= K <= 1050 <= arr[i] <= 105ExampleInput24 31 7 2 4 5 21 2 3 4 5Output32ExplanationTest Case 1:The subset {1, 7, 4} is the largest subset with the sum of any two numbers { {1,7}=8, {1,4}=5, {7,4}=11 } not perfectly divisible by K=3.Test Case 2:The subset {1, 2} or {2, 3} or {3, 4} or {4, 5} can be the largest subset with the sum of any two numbers not perfectly divisible by K=2.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a step-by-step solution to the problem:

  1. Initialize an array of size K to zero. This array will be used to store the remainders when the array elements are divided by K.

  2. Iterate through the given array. For each

Similar Questions

Sum of 2 NumbersGiven an array, check if there exist 2 elements of the array such that their sum is equal to the sum of the remaining elements of the array.Input FormatThe first line of input contains T - the number of test cases. It is followed by 2T lines, the first line contains N - the size of the array. The second line contains N integers - elements of the array.Output FormatFor each test case, print "Yes" if such elements exist, and "No" otherwise, separated by a new line.

Given an array A of N integers and an integer K, write a program to print the number of subarrays in A whose sum is divisible by K.

You are given an integer array and a positive integer K. You have to tell if there exists i,j,k in the given array such that ar[i]+ar[j]+ar[k]=K, i≠j≠k.Input FormatThe first line of input contains T - the number of test cases. Its followed by 2T lines, the first line contains N and K - the size of the array and the number K. The second line contains the elements of the array.Output FormatFor each test case, print "true" if the arrays contains such elements, false otherwise, separated by new line.Constraints30 points1 <= T <= 1003 <= N <= 10070 points1 <= T <= 1003 <= N <= 1000General Constraints-100000 <= A[i] <= 1000000 <= K <= 100000ExampleInput35 601 20 40 100 8012 5412 45 52 65 21 645 234 -100 14 575 -80 1123 155 5 5Outputfalsetruetrue

You are given an array 𝐴A of size 𝑁N.Find the largest integer 𝐾K such that there exists a subsequence 𝑆S of length 𝐾K where 𝐾K is divisible by the number of distinct elements in 𝑆S.Input FormatThe first line contains a single integer 𝑇T, denoting the number of test cases.The first line of each test case contains a positive integer 𝑁N, the length of array 𝐴A.The second line contains 𝑁N space-separated integers, 𝐴1,𝐴2,…,𝐴𝑁A 1​ ,A 2​ ,…,A N​ −− denoting the array 𝐴A.Output FormatFor each test case, output the largest valid 𝐾K.Constraints1≤𝑇≤1041≤T≤10 4 1≤𝐴𝑖≤𝑁≤2⋅1051≤A i​ ≤N≤2⋅10 5 The sum of 𝑁N over all test cases won't exceed 2⋅1052⋅10 5 .Sample 1:

Given an array of integers, find the largest number that can be constructed by concatenating all the elements of the given array.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines. The first line of each test case contains N - the size of the array and the second line contains N integers - the elements of the array.Output FormatFor each test case, print the largest number that can be constructed by concatenating all the elements of the given array, separated by a new line.Constraints1 <= T <= 10001 <= N <= 10000 <= ar[i] <= 1000ExampleInput3849 73 58 30 72 44 78 23469 9 57 60240 4Output78737258494430239696057440

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.