CSES - Components

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

For example there is an edge between the nodes 44 and 1212, because 1212 is divisible by 44. There is no edge between the nodes 33 and 1313.

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

The number of components:

The code you used: