- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two numbers p and q. We have to check whether the sum of all divisors of these tow numbers are same or not.

So, if the input is like p = 559, q = 703, then the output will be True the divisors of 559 is 1, 13, 43 and 703 is 1, 19, 37. The sum of the divisors are 57.

To solve this, we will follow these steps −

- Define a function divSum() . This will take n
- total := 1
- i := 2
- while i * i <= n, do
- if n divisible by i, then
- total := total + i + the floor of (n / i)

- i := i + 1

- if n divisible by i, then
- return total
- From the main method return true when divSum(p) is same as divSum(q), otherwise false

Let us see the following implementation to get better understanding −

from math import floor def divSum(n): total = 1 i = 2 while i * i <= n: if n % i == 0: total += i + floor(n / i) i += 1 return total def solve(p, q): return divSum(p) == divSum(q) p = 559 q = 703 print(solve(p, q))

559, 703

True

- Related Questions & Answers
- Check if binary representations of two numbers are anagram in Python
- Python Program for Common Divisors of Two Numbers
- Python Program to Check If Two Numbers are Amicable Numbers
- Python program to check if binary representation of two numbers are anagram.
- Python Pandas – Check if two Dataframes are exactly same
- Check if values of two arrays are the same/equal in JavaScript
- Check if leaf traversal of two Binary Trees is same in Python
- Program to count number of common divisors of two numbers in Python
- Check if two list of tuples are identical in Python
- Check if a prime number can be expressed as sum of two Prime Numbers in Python
- Golang Program to check if two numbers are Amicable Numbers
- C++ Program for Common Divisors of Two Numbers?
- Java Program for Common Divisors of Two Numbers
- Java program to check if binary representations of two numbers are anagram
- Check if count of divisors is even or odd in Python

Advertisements