fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long gcd(long long a, long long b){
  4. return (b == 0)? a: gcd(b, a%b);
  5. }
  6. int main()
  7. {
  8. int t;
  9. cin>>t;
  10. while(t--){
  11. long long n;
  12. cin>>n;
  13. vector<long long> v(n), co(n);
  14. for(int x = 0; x <n; x++)
  15. cin>>v[x];
  16. int cnt = 0;
  17. for(int x = 0; x< n; x++){
  18. if(co[x]) continue;
  19. for(int y = x; y < n; y++){
  20. if(!co[y] && gcd(v[x], v[y]) > 1)
  21. co[y] = cnt;
  22. }
  23. co[x] = ++cnt;
  24. }
  25. cout<<cnt<<endl;
  26. for(int i = 0; i < n; i++){
  27. cout<<co[i]<<" ";
  28. }
  29. cout<<endl;
  30. }
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5520KB
stdin
Standard input is empty
stdout
Standard output is empty