Canada Numbers | Function to calculate sum of all trivial divisors of given natural number ; Final result of summation of trivial divisors ; Find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Function to return sum of squares of digits of N ; Function to check if N is a Canada number ; Given Number ; Function Call
function divSum ( num ) { let result = 0 ; for ( let i = 1 ; i <= Math . sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return ( result - 1 - num ) ; } function getSum ( n ) { let sum = 0 ; while ( n != 0 ) { let r = n % 10 ; sum = sum + r * r ; n = parseInt ( n / 10 ) ; } return sum ; } function isCanada ( n ) { return divSum ( n ) == getSum ( n ) ; } let n = 125 ; if ( isCanada ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;