-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompositecoloring.java
More file actions
41 lines (40 loc) · 1.19 KB
/
compositecoloring.java
File metadata and controls
41 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;
import java.util.*;
import java.awt.*;
public class compositecoloring {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
StringBuilder sb=new StringBuilder();
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)arr[i]=sc.nextInt();
int[] res = new int[n];
int[] primes = {2,3,5,7,11,13,17,19,23,29,31};
int col = 1;
for(int p: primes)
{
ArrayList<Integer> loc = new ArrayList<Integer>();
for(int i=0; i < n; i++)
{
int x = arr[i];
if(x%p == 0 && res[i] == 0)
loc.add(i);
}
if(loc.size() > 0)
{
for(int x: loc)
res[x] = col;
col++;
}
}
sb.append(col-1);
sb.append("\n");
for(int x: res)
sb.append(x+" ");
sb.append("\n");
}
System.out.print(sb);
}
}