fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. #define pb emplace_back
  4. #define mp make_pair
  5. #define x first
  6. #define y second
  7. #define all(a) a.begin(), a.end()
  8. #define rall(a) a.rbegin(), a.rend()
  9. typedef long double ld;
  10. typedef long long ll;
  11. using namespace std;
  12. mt19937 rnd(time(nullptr));
  13.  
  14. signed main()
  15. {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(nullptr);
  18. cout.tie(nullptr);
  19. int t; cin >> t;
  20. while (t--)
  21. {
  22. int n ; cin >> n;
  23. int k; cin >> k;
  24. vector<int> v(n);
  25. for (int i = 0; i < n; i++)
  26. {
  27. int x; cin >> x;
  28. v[i] = x%k;
  29. if(v[i] == 0) cout << i+1 << " ";
  30. }
  31. // 2 2 0 2
  32. int x = k-1;
  33. while (x >= 1)
  34. {
  35. for (int i = 0; i < n; i++)
  36. {
  37. if(v[i] == x){
  38. cout << i+1 << " ";
  39. }
  40. }
  41. x--;
  42. }
  43.  
  44. cout << endl;
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 5312KB
stdin
3
3 2
1 2 3
2 3
1 1
4 3
2 8 3 5
stdout
2 1 3 
1 2 
3 1 2 4