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.
Strange Counter
Strange Counter
+ 0 comments My java solution
public static long strangeCounter(long t) { long n = 4; while(t >= n) { n = (n*2) + 2; } return n-t; }
+ 0 comments My C# Solution
public static long strangeCounter(long t) { int n = 0; long lastT = t; long cycleTime = int.MinValue; do { lastT = t; cycleTime = 3 * (long) Math.Pow((2), n); if( t <= cycleTime) return cycleTime - t + 1; t -= cycleTime; n++; } while (lastT >= cycleTime); return 0; }
+ 0 comments Here is my c++ solution, you can watch the explanation here : https://youtu.be/Plsx1i8dqiI
long strangeCounter(long t) { long last = 3, step = 3; while(t > last){ step *= 2; last += step; } return last - t + 1; }
+ 0 comments c++ sl
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ int t; int i=3; int temp=3; cin>>t; while(1) { if(temp>=t) { t= (temp-t)+1; break; } i=i*2; temp+=i; } cout<<t; }
+ 0 comments t = int(input())
t_lower = 1
while t_lower<=t: tmp = t_lower t_lower = (t_lower*2)+2
t_lower = tmp v_lower = t_lower+2
t_higher = t_lower+(v_lower-1) v_higher = 1
ls = [] vs = []
for i in range(t_lower, t_higher+1, 1): ls.append(i)
for i in range(v_lower, 0, -1): vs.append(i)
req_index = ls.index(t)
Why is it giving runtime error in some tescases
print(vs[req_index])
why
Load more conversations
Sort 903 Discussions, By:
Please Login in order to post a comment