Advertisement
tumaryui

Untitled

Mar 31st, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. main() {
  5. int t;
  6. cin >> t;
  7. while(t--) {
  8. int n;
  9. cin >> n;
  10. int a[n];
  11. for(int i = 0; i < n; i++) {
  12. cin >> a[i];
  13. }
  14. int col = 1;
  15. int ans[n] = {0};
  16. int rest = n;
  17. for(int i = 2; rest > 0; i++) {
  18. bool ok = 0;
  19. bool ch = 0;
  20. for(int j = 0; j < n; j++) {
  21. if(!ans[j] && a[j] % i == 0) {
  22. ch = 1;
  23. rest--;
  24. ans[j] = col;
  25. }
  26. if(rest == 0) {
  27. ok = 1;
  28. break;
  29. }
  30. }
  31. if(ok) break;
  32.  
  33. if(ch) col++;
  34. }
  35. cout << col << endl;
  36. for(int i = 0; i < n; i++) {
  37. cout << ans[i] << " ";
  38. }
  39. puts("");
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement