public int count(int n){
        if(n < 4){
            return n;
        }
        if( n >=4 && n <=10){
            return n-1;
        }
        
        int pow = 1;
        while(n/pow > 9){
            pow = pow*10;
        }
        
        int msd = n/pow;
        if(msd == 4){
            return count(msd*pow -1);
        }else{
            //suppose number is 276. So this becomes count(2)*count(99) +
            //count(2) + count(76)
            //reason we split this way rather than count(2)*count(100) is because
            //count(100) can go into infinite loop
            return count(msd)*count(pow-1) + count(msd) + count(n%pow);
        }
    }
http://www.geeksforgeeks.org/count-numbers-that-dont-contain-3/
src/com/interview/number/CountNumbersNotIncluding4.java