Count By Remainders
Python
Medium
4 views
Problem Description
For each testcase you get n, m and n integers. Count how many numbers give remainder 0..m-1 when divided by m. Output counts in one line.
Input Format
First integer t. For each: n m then n integers.
Output Format
t lines of m counts.
Sample Test Case
Input:
1
7 3
1 2 3 4 5 6 7
Constraints
Sum of n over all testcases
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p:
sys.exit(0)
it=iter(p)
t=int(next(it))
out=[]
for _ in range(t):
n=int(next(it)); m=int(next(it))
cnt=[0]*m
for i in range(n):
x=int(next(it))
cnt[x%m]+=1
out.append(' '.join(map(str,cnt)))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!