XxOoRr (XXOORR) Solution — Codechef July Long Challenge

Input

Output

Constraints

Subtasks

Sample Input

1
3 2
3 6 10

Sample Output

5

Explanation

/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();

while(t-->0){
int n = sc.nextInt();
int k = sc.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
int sum[] = new int[33]; for(int i=0;i<n;i++){
int x = arr[i];
int j = 32;
while(x>0){
sum[j] += (x%2);
j--;
x /= 2;
}
}
int cnt=0;
for(int i=0;i<33;i++){
if(sum[i]%k==0){
cnt+= sum[i]/k;
}else{
cnt+= sum[i]/k;
cnt+=1;
}
}
System.out.println(cnt);
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store