Sort by

recency

|

1002 Discussions

|

  • + 0 comments

    Python without loop

    def strangeCounter(t):
        # Write your code here
        r = math.ceil(math.log2(t/3+1)) # Calculate the number of current round
        sum_full = 3*(2**r-1) # Calculate the time when value reach to 1 at current round
        return sum_full - t + 1
    
  • + 0 comments

    long strangeCounter(long t) { long b = 1, tmp = 3, idx = 3, j; while (idx < t){ b += tmp; tmp *= 2; idx += tmp; } j = t - b + 1; return tmp - j + 1; }

  • + 0 comments

    def strangeCounter(t):! start=1 end=3 no = 3 ans=0 while(endend): break start = start+no no = no*2 end = end+no ans = 1+(end-t) return ans

  • + 0 comments

    return 6 * (2 ** math.floor(math.log2(1 + (t - 1) / 3))) - 2 - t

  • + 0 comments
    #include <bits/stdc++.h>
    
    using namespace std;
    
    string ltrim(const string &);
    string rtrim(const string &);
    
    /*
     * Complete the 'strangeCounter' function below.
     *
     * The function is expected to return a LONG_INTEGER.
     * The function accepts LONG_INTEGER t as parameter.
     */
    
    long strangeCounter(long t) {
        if(t==1)
        {
            return 3;
        }
        else if(t==2)
        {
            return 2;
        }
        else if(t==3)
        {
            return 1;
        }
        else
        {
            long it=3,i=6;
        while(it<t)
        {
            it=it+i;
            i=i*2;
        }
        long diff=it-t;
        return diff+1;
        }
        
    }
    int main()
    {
        ofstream fout(getenv("OUTPUT_PATH"));
    
        string t_temp;
        getline(cin, t_temp);
    
        long t = stol(ltrim(rtrim(t_temp)));
    
        long result = strangeCounter(t);
    
        fout << result << "\n";
    
        fout.close();
    
        return 0;
    }
    
    string ltrim(const string &str) {
        string s(str);
    
        s.erase(
            s.begin(),
            find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
        );
    
        return s;
    }
    
    string rtrim(const string &str) {
        string s(str);
    
        s.erase(
            find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
            s.end()
        );
    
        return s;
    }