Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <deque>
#include <set>

using namespace std;

#define speedup ios::sync_with_stdio(0),cin.tie(0);

long long int power(long long int b,long long int p)
{
    long long int y=1;
    for(int i=1;i<=p;i++)
    {
        y*=b;
    }
    return y;
}

template<typename t>
t gcd(t a,t b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}

int main()
{
    speedup;

    int t;
    cin>>t;
    long long int n;
    while(t--)
    {
        cin>>n;
        long long int x=1,y,nt=0,ans=0,notin=0;
        while(n!=1)
        {
            nt=0;
            while(n!=0)
            {
                x = floor(log2(n));
                y=power(2,x);
                nt++;
                n = n - y;
            }
            notin+=nt-1;
            ans+=nt;
            n=nt;
        }
        long long int h=gcd(notin,ans);
        cout<<notin/h<<" / "<<ans/h<<endl;
    }


    return 0;
}
Copy
The Complete tournament maenobaid
GNU G++17
352 ms
1.5 MB
Accepted