CSES - Components

Consider a graph with the nodes 2,3,\dots,N. Two nodes a and b are connected by an edge if a is divisible by b or b is divisible by a.

For example there is an edge between the nodes 4 and 12, because 12 is divisible by 4. There is no edge between the nodes 3 and 13.

Write a program that computes the number of components in the graph when N=1000.

The number of components:

The code you used: