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.
longstrangeCounter(longt){/*The time value at which each increase in value occurs is given by the sum of n terms of a geometric progression, and the new maximum value is the nth term of this progression with a1 = 3 and r = 2. So you can get n from the Sn equation (sum of n terms) and work with it*/longresult=0,max_time;intn=log2(t/3+1)/log2(2);max_time=max_time=(t<=-3*(1-pow(2,n)))?-3*(1-pow(2,n)):-3*(1-pow(2,n+1));result=max_time-t+1;returnresult;}
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 →
C++