forked from prosoftwaredevelopment/CompetetiveCodingPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivisors.py
More file actions
33 lines (29 loc) · 632 Bytes
/
divisors.py
File metadata and controls
33 lines (29 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 24 [1,2,3,4,6,8,12,24]
# n = 24 T.C = o(n) = 24
# n = 24 T.C = root(n) = 4.89
from math import *
def fun1(n):
# T.C = O(n)
div1 = []
for i in range(1,n+1): # [1,n]
if n%i == 0:
div1.append(i)
return div1
def fun2(n):
# T.C = O(root(n))
div2 = set()
for i in range(1,int(sqrt(n))+1): # [1,root(n)]
if n%i == 0:
div2.add(i)
div2.add(n//i)
return list(div2)
# root(n) is a efficient program
# T.C O(n) > O(root(n))
t = int(input())
while t:
n = int(input())
div1 = fun1(n)
print(*div1)
div2 = fun2(n)
print(*div2)
t=t-1