I think it's worth illustrating the role of $\mu(n)$, The Möbius function, in inclusion-exclusion as Barry Cipra alludes to.
We will calculate $Q(N)$. For the $i$th prime $p_i$ (considering only $p_i^2 \le N$) let
$$A_i = \{p_i^2, 2p_i^2, \dots, p_i^2 \lfloor N / p_i^2 \rfloor \}$$
For example $A_1 = \{4, 8, 12, 16, \dots, 4 \lfloor N/4 \rfloor \}$, the multiples of $4$ that are less than or equal to $N$.
We are looking for $$N - \left\vert \bigcup_{i} A_i \right\vert =
N
- \left( \sum_{i} |A_i| \right)
+ \left( \sum_{i < j} |A_i \cap A_j| \right)
- \left( \sum_{i < j < k} |A_i \cap A_j \cap A_k| \right)
+ \cdots $$
We see that $A_1 \cap A_2$ are numbers that are divisible by $4$ and $9$, or divisible by $36$. Similarly $A_1 \cap A_3$ are numbers divisible by $4 \times 25$ and $A_2 \cap A_3$ are numbers divisible by $9 \times 25$. $A_1 \cap A_2 \cap A_3$ are numbers divisible by $4 \times 9 \times 25$.
Directly from the inclusion-exclusion formula, we see we subtract out numbers that are the product of an odd number of squared (distinct) primes, and add in numbers that are the product of an even number of squared (distinct) primes. Let's say $n^2$ is this product of these squared primes. Then $n$ is the product of distinct primes. There are $\lfloor N/n^2 \rfloor$ of these values (see Kieren MacMillan's answer).
$\mu(n)$ is $-1$ when $n$ is the product of an odd number of distinct primes, $1$ when $n$ is the product of an even number of distinct primes, and $0$ if $n$ is not the product of distinct primes ($n$ is not square-free). This corresponds exactly to the adding and subtracting in our inclusion-exclusion formula! (Note that $\mu(n)=0$ means $n$ is not the product of distinct primes, and so is not considered in the inclusion-exclusion formula).
So we conclude that $\mu(n)$ is a handy way of encoding our inclusion-exclusion principle. $$Q(N) = \sum_{n=1}^{\lfloor \sqrt N \rfloor} \mu(n) \left\lfloor \frac{N}{n^2} \right\rfloor$$
To actually calculate $Q(N)$ we need $\mu(n)$ values up to $\sqrt N$. A variation of the Sieve of Eratosthenes calculates a range of $\mu(n)$ much more efficiently than calculating one value at a time. Algorithms listed on MO.