Connected Components

4.7

3 votes
Algorithms, Graphs, Graph Representation
Problem

You are given an undirected simple graph G containing exactly n distinct nodes.

The nodes are numbered from 1 to n.

Suppose that (u,v) is an edge of G if and only if uv is a perfect square.

Please compute the number of the connected components of G.

 

Input Format

  • The first line contains a single integer T — the number of test cases.
  • Each test case consists one positive integer n — the number of distinct nodes.

Output Format

  • For each testcase, output the number of the connected components of G.

 Constraints

  • 1T104
  • 1n2105
  • The sum of n over all test cases does not exceed 107.
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

For the 4th case, since 14=4=22, the node 4 is connected to node 1.

Editor Image

?