Py|| Friendly number

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Lhw_666/article/details/102738879

题目描述
There are two integers a snd b. If the sum of b’s divisors equals to a, and the sum of a’s divisors equals to b, we call these two integers are “Friendly numbers”.

E.g:

  1. 9 and 4
    The sum of 9’s divisors is: 1 + 3 = 4
    The sum of 4s divisors is: 1 + 2 = 3
    So 9 and 4 are not Friendly numbers.

  2. 284 and 220
    The sum of 220’s divisors is: 1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110=284
    The sum of 284’s divisors is: 1 + 2 + 4 + 71 + 142=220

So 220 and 284 are Friendly numbers.

Write a program to determine if the two numbers are friendly numbers.

输入
Two integers, separated by spaces. (Two integers are less than 10000)
输出
If it is a friendly number, output “yes”, otherwise output “no”, note that no quotes are included.
样例输入 Copy
220 284
样例输出 Copy
yes

a,b=map(int,input().split())
s1=0
s2=0
for i in range(1,a):
    if a%i==0:
        s1=s1+i
for i in range(1,b):
    if b%i==0:
        s2=s2+i
if s1==b and s2==a:
    print('yes')
else:
    print('no')

猜你喜欢

转载自blog.csdn.net/Lhw_666/article/details/102738879
py