- Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathamicable-pair.py
More file actions
Latest commit
28 lines (26 loc) · 662 Bytes
/
Copy pathamicable-pair.py
File metadata and controls
28 lines (26 loc) · 662 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
classSolution:
"""
@param: k: An integer
@return: all amicable pairs
"""
defamicablePair(self, k):
# write your code here
ret= []
foriinrange(2, k+1):
s=self.vsum(i)
if (s<=i) or (s> (k+1)):
continue
ifi==self.vsum(s):
ret.append([i, s])
returnret
defvsum(self, v):
ret=1
i=2
whilei*i<v:
ifv%i==0:
ret+= (i+int(v/i))
i+=1
ifi*i==v:
ret+=i
returnret
# easy: https://www.lintcode.com/problem/243