We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
constant time ..
long cycle = Double.valueOf(Math.ceil(Math.log((new Double(t) + 3) / 3) / Math.log(2))).longValue();
double p = Math.pow(2, cycle - 1);
long start = 3 * new Double(p).longValue();
long rem = t - (3 * (new Double(p).longValue() - 1));
return start - (rem - 1);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strange Counter
You are viewing a single comment's thread. Return to all comments →
constant time .. long cycle = Double.valueOf(Math.ceil(Math.log((new Double(t) + 3) / 3) / Math.log(2))).longValue(); double p = Math.pow(2, cycle - 1); long start = 3 * new Double(p).longValue(); long rem = t - (3 * (new Double(p).longValue() - 1)); return start - (rem - 1);