ExamAdda Logo

Print All Divisors

Easy

Given a positive integer n, print all the divisors of n in increasing order.

A divisor of a number n is an integer that divides n completely without leaving any remainder.

Return or print all divisors separated by a single space.

Example 1

Input

12

Output

1 2 3 4 6 12

Explanation

The numbers 1, 2, 3, 4, 6, and 12 divide 12 without leaving a remainder.
Therefore, these are all the divisors of 12.

Example 2

Input

36

Output

1 2 3 4 6 9 12 18 36

Explanation

These are all the positive integers that divide 36 exactly without leaving a remainder.

Constraints

1 ≤ n ≤ 10^9

Hints:

Hint 1

Divisors occur in pairs. If i divides n, then n / i is also a divisor. You only need to check values up to the square root of n, then arrange the divisors in increasing order.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Jul 20, 2026

Last updated

Aug 6, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output