Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
12
Task/Amicable-pairs/Python/amicable-pairs.py
Normal file
12
Task/Amicable-pairs/Python/amicable-pairs.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from proper_divisors import proper_divs
|
||||
|
||||
def amicable(rangemax=20000):
|
||||
n2divsum = {n: sum(proper_divs(n)) for n in range(1, rangemax + 1)}
|
||||
for num, divsum in n2divsum.items():
|
||||
if num < divsum and divsum <= rangemax and n2divsum[divsum] == num:
|
||||
yield num, divsum
|
||||
|
||||
if __name__ == '__main__':
|
||||
for num, divsum in amicable():
|
||||
print('Amicable pair: %i and %i With proper divisors:\n %r\n %r'
|
||||
% (num, divsum, sorted(proper_divs(num)), sorted(proper_divs(divsum))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue