Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- main() {
- int t;
- cin >> t;
- while(t--) {
- int n;
- cin >> n;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int col = 1;
- int ans[n] = {0};
- int rest = n;
- for(int i = 2; rest > 0; i++) {
- bool ok = 0;
- bool ch = 0;
- for(int j = 0; j < n; j++) {
- if(!ans[j] && a[j] % i == 0) {
- ch = 1;
- rest--;
- ans[j] = col;
- }
- if(rest == 0) {
- ok = 1;
- break;
- }
- }
- if(ok) break;
- if(ch) col++;
- }
- cout << col << endl;
- for(int i = 0; i < n; i++) {
- cout << ans[i] << " ";
- }
- puts("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement