Count integers in a range which are divisible by their euler totient value | C ++ implementation of the above approach . ; Function to return a ^ n ; Function to return count of integers that satisfy n % phi ( n ) = 0 ; Driver Code
#include <bits/stdc++.h> NEW_LINE #define ll  long long NEW_LINE using namespace std ; ll power ( ll a , ll n ) { if ( n == 0 ) return 1 ; ll p = power ( a , n / 2 ) ; p = p * p ; if ( n & 1 ) p = p * a ; return p ; } int countIntegers ( ll l , ll r ) { ll ans = 0 , i = 1 ; ll 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 ans ; } int main ( ) { ll l = 12 , r = 21 ; cout << countIntegers ( l , r ) ; return 0 ; }