Special graphs

2.9

9 votes
Algorithms, C++, Graphs, Sieve
Problem

There exist a graph with N nodes that are numbered from 1 to N. There exists an edge between two nodes (u, v). Now, u!=v if u divides v or vice versa. Node 1 is not connected to any other node.

Find the minimum size of set S of nodes such that all the nodes of this graph except node 1 is covered by this set. A node is said to be covered if it is present in this set or there exists at least one node in the set with which it is directly connected, that is, there is an edge between them.

You must cover all the nodes but not the edges.

Input format

  • The first line contains an integer Q denoting the number of queries.
  • The next Q lines contain an integer N denoting the number of nodes in the graph.

Output format

Print the minimum size of set S for each query in a separate line.

Constraints
1Q1e52N1e6

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Graph will have following edges

2-4 , 2-6, 3-6. 

One possible set S will be = {4,6,5} . |S| = 3

:
 

Editor Image

?