Count divisors which generates same Quotient and Remainder | Function to calculate the count of numbers such that it gives same quotient and remainder ; Stores divisor of number N . ; Iterate through numbers from 2 to sqrt ( N ) and store divisors of N ; As N is also divisor of itself ; Iterate through divisors ; Checking whether x satisfies the required condition ; Print the count ; Given N ; Function Call
function countDivisors ( n ) { var count = 0 ; var j = 0 ; var divisor = Array ( n ) . fill ( 0 ) ; for ( var i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( parseInt ( n / i ) == i ) { divisor [ j ] = i ; j += 1 ; } else { divisor [ j ] = i ; divisor [ j + 1 ] = parseInt ( n / i ) ; j += 2 ; } } } divisor [ j ] = n ; for ( var i = 0 ; i <= j ; i ++ ) { var x = divisor [ i ] ; x -= 1 ; if ( parseInt ( n / x ) == parseInt ( n % x ) ) count ++ ; } document . write ( count ) ; } var N = 10000000 ; countDivisors ( N ) ;