• + 0 comments

    C++ Solution with recurse:

    long defRange(long t, long p, long it) {
      long b = (long)3*pow(2, it++) + p;
    
      if (t >= p && t < b)
        return b;
      else
        return defRange(t, b, it);
    }
    
    // res = -t * b[n] : b[n] = 3*pow(2,n) + b[n-1]
    long strangeCounter(long t) {
      long b = defRange(t, 1, 0);
      
      return -t+b;
    }