Skip to content

Commit daa539a

Browse files
authored
O(√n)
return all divisors of the number "n" in time complexity O(√n)
1 parent be7a97f commit daa539a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

divisors

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from math import *
2+
3+
4+
def divisors(n):
5+
div = set()
6+
for i in range(1,int(sqrt(n))+1):
7+
if n%i == 0:
8+
div.add(i)
9+
div.add(n//i)
10+
return list(div)
11+
12+
13+
for _ in range(int(input())):
14+
n = int(input())
15+
print(*divisors(n))

0 commit comments

Comments
 (0)