Divisors in order P39308


Statement
 

pdf   zip

html

Write a program to print in order all the divisors of a given number.

Input

Input consists of several cases, each with a natural number n between 1 and 109.

Output

For every n, print the divisors of n in increasing order.

Observations

  • Your program must be “efficient” to be accepted by the judge.
  • You are not allowed to use vectors or alike.

Hint

Every divisor smaller than the square root of n has a corresponding divisor greater than the square root of n. It could be useful to make two loops, one for “small” divisors, and another for “large” divisors.

Public test cases
  • Input

    200
    6
    1
    100
    999999998
    999999937
    

    Output

    divisors of 200: 1 2 4 5 8 10 20 25 40 50 100 200
    divisors of 6: 1 2 3 6
    divisors of 1: 1
    divisors of 100: 1 2 4 5 10 20 25 50 100
    divisors of 999999998: 1 2 691 1382 723589 1447178 499999999 999999998
    divisors of 999999937: 1 999999937
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C C++ Python