Square-Free Sequence

Medium
number-theory prime-factorization sieve math
Problem Description

Generate the first N square-free numbers. A square-free number is a positive integer that is not divisible by any perfect square other than 1. In other words, no prime factor appears more than once in its prime factorization.

Input Format
A single integer N.
Output Format
The first N square-free numbers, space-separated on one line.
Constraints
• 1 ≤ N ≤ 1000
• Square-free means not divisible by 4, 9, 16, 25, 36, 49, ...
• 1 is considered square-free
• Output numbers in ascending order
• Efficient prime factorization recommended
Sample Input/Output
Input:
10
Output:
1 2 3 5 6 7 10 11 13 14
Explanation

First 10 square-free numbers: 1 (no prime factors), 2 (prime), 3 (prime), 5 (prime), 6 (2×3), 7 (prime), 10 (2×5), 11 (prime), 13 (prime), 14 (2×7). Numbers like 4 (2²), 8 (2³), 9 (3²), 12 (2²×3) are not square-free.

Solution Hints
100
Points
3000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback