Baseline Bit Manipulation · Advanced Maths O(sqrt(n)) · O(sqrt(n)) for the large-half scratch list
A cable crew must list every equal-length cut possible for a coil of length n, in ascending order. Scanning all lengths up to n wastes a shift; instead the crew checks lengths only up to the square root and records each complementary length — n divided by the small one — on a scratch list, then reads the scratch list backwards so the full catalogue ascends.
Input: An integer n.
Output: All divisors of n in ascending order.
1 <= n <= 10^9Input: {"n":20}
Output: [1,2,4,5,10,20]
Small cuts 1, 2, 4 pair with large cuts 20, 10, 5; merged, the list ascends.
Input: {"n":36}
Output: [1,2,3,4,6,9,12,18,36]
The square root 6 is a divisor exactly once — never list it twice.