Count integers in a range which are divisible by their euler totient value | Function to return a ^ n ; Function to return count of integers that satisfy n % phi ( n ) = 0 ; Driver Code
function power ( a , n ) { if ( n == 0 ) return 1 ; var p = power ( a , parseInt ( n / 2 ) ) ; p = p * p ; if ( n % 2 == 1 ) p = p * a ; return p ; } function countIntegers ( l , r ) { var ans = 0 , i = 1 ; var v = power ( 2 , i ) ; while ( v <= r ) { while ( v <= r ) { if ( v >= l ) ans ++ ; v = v * 3 ; } i ++ ; v = power ( 2 , i ) ; } if ( l == 1 ) ans ++ ; return parseInt ( ans ) ; } var l = 12 , r = 21 ; document . write ( countIntegers ( l , r ) ) ;