• + 0 comments

    Java

    public static long strangeCounter(long t) {
        // Write your code here
            //3*2^0 + 3 * 2^1 + 3*2^n
            long x = 0L;
            long i = 0L;
            long s = 0L;
            long k = 1L;
            while(x < t){
                x = (long)(3 * Math.pow(2,i));
                k += x;
                if(k > t) {
                    s = k - t;
                    break;
                } 
                i++;
            }
            return s;
        }