fork download
  1. # your code goes here
  2. import math
  3.  
  4. def get_divisors(n):
  5. divisors = []
  6. for i in range(1, int(math.isqrt(n)) + 1):
  7. if n % i == 0:
  8. divisors.extend({i, n // i}) # Use a set to avoid duplicate square roots
  9. return sorted(divisors, reverse=True)
  10.  
  11. # Example usage
  12. print(*get_divisors(12))
Success #stdin #stdout 0.07s 14024KB
stdin
Standard input is empty
stdout
12 6 4 3 2 1