Find the number of integers x in range ( 1 , N ) for which x and x + 1 have same number of divisors | Javascript implementation of the approach ; To store number of divisors and Prefix sum of such numbers ; Function to find the number of integers 1 < x < N for which x and x + 1 have the same number of positive divisors ; Count the number of divisors ; Run a loop upto sqrt ( i ) ; If j is divisor of i ; If it is perfect square ; x and x + 1 have same number of positive divisors ; Function call ; Required answer
const N = 100005 ; let d = new Array ( N ) . fill ( 0 ) ; let pre = new Array ( N ) . fill ( 0 ) ; function Positive_Divisors ( ) { for ( let i = 1 ; i < N ; i ++ ) { for ( let j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( j * j == i ) d [ i ] ++ ; else d [ i ] += 2 ; } } } let ans = 0 ; for ( let i = 2 ; i < N ; i ++ ) { if ( d [ i ] == d [ i - 1 ] ) ans ++ ; pre [ i ] = ans ; } } Positive_Divisors ( ) ; let n = 15 ; document . write ( pre [ n ] ) ;