fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. signed main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int tt;
  9. cin >> tt;
  10. bool ok = false;
  11. while (tt--) {
  12. if (ok)
  13. cout << "\n";
  14. int m, n;
  15. cin >> m >> n;
  16. vector<vector<int>> hash(m);
  17. for (int i = 0; i < n; i++) {
  18. int x;
  19. cin >> x;
  20. hash[x % m].push_back(x);
  21. }
  22. for (int i = 0; i < m; i++) {
  23. cout << i << " -> ";
  24. for (auto x : hash[i])
  25. cout << x << " -> ";
  26. cout << "\\\n";
  27. }
  28. ok = true;
  29. }
  30. }
Success #stdin #stdout 0s 544KB
stdin
2
13 9
44 45 49 70 27 73 92 97 95
7 8
35 12 2 17 19 51 88 86
stdout
0 -> \
1 -> 27 -> 92 -> \
2 -> \
3 -> \
4 -> 95 -> \
5 -> 44 -> 70 -> \
6 -> 45 -> 97 -> \
7 -> \
8 -> 73 -> \
9 -> \
10 -> 49 -> \
11 -> \
12 -> \

0 -> 35 -> \
1 -> \
2 -> 2 -> 51 -> 86 -> \
3 -> 17 -> \
4 -> 88 -> \
5 -> 12 -> 19 -> \
6 -> \