- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if two numbers (m,n) are amicable or not using Python?
Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper divisors of 6 are 1, 2, and 3.)
In python, you can find these numbers by taking the sum of each of these and comparing them with the other. For example,
def are_amicable(x, y) if x==y: return False # Find sum of their proper divisors sum_x = sum(e for e in range(1, x//2+1) if x % e == 0) sum_y = sum(e for e in range(1, y//2+1) if y % e == 0) #Return true of they satisfy the last condition return sum_x==y and sum_y==x print(are_amicable(15, 20)) print(are_amicable(220, 284))
This will give the output
False True
- Related Articles
- Python Program to Check If Two Numbers are Amicable Numbers
- Golang Program to check if two numbers are Amicable Numbers
- How to check if a file exists or not using Python?
- C++ Program to check if given numbers are coprime or not
- C Program to check if two strings are same or not
- Golang Program to Check If Two Arrays are Equal or Not
- Swift Program to Check if Two Arrays Are Equal or Not
- Check if bits in range L to R of two numbers are complement of each other or not in Python
- Check if all levels of two trees are anagrams or not in Python
- Program to check if array pairs are divisible by k or not using Python
- Check if two strings are equal or not in Arduino
- Python Pandas – Check if any specific column of two DataFrames are equal or not
- Program to check whether two sentences are similar or not in Python
- Check if two StringDictionary objects are equal or not in C#
- Check if a string follows a^n b^n pattern or not in Python

Advertisements