Check if sum of divisors of two numbers are same | C ++ program to find if two numbers are equivalent or not ; Function to calculate sum of all proper divisors num -- > given natural number ; To store sum of divisors ; Find all divisors and add them ; Function to check if both numbers are equivalent or not ; Drivers code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int divSum ( int n ) { long long int sum = 1 ; for ( long long int i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) sum = sum + i + n / i ; return sum ; } bool areEquivalent ( int num1 , int num2 ) { return divSum ( num1 ) == divSum ( num2 ) ; } int main ( ) { int num1 = 559 , num2 = 703 ; areEquivalent ( num1 , num2 ) ? cout << " Equivalent " : cout << " Not ▁ Equivalent " ; return 0 ; }