Link to the problem: CFD021 Problem - CodeChef
My c++ code is linked below
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define llf long long float
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define u_m unordered_map
#define limit pow(10,6)
int intlog(double x) {
return floor((lli)(log(x) / log(3)));
}
int main()
{
IOS;
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
#endif
set<int>s;double x,save;int t,q=0;cin>>t;
while(t--)
{
cin>>x;long long int p;save=x;
while(x>0)
{
p=intlog(x);x-=pow(3,p);
if(p==0) continue;
else if(s.find(p)==s.end()) s.insert(p);
else s.erase(p);
}
set<int>::iterator it;
for(it=s.begin();it!=s.end();++it)
q^=*it;
lli ans = q>0 ? pow(3,q):0;
cout<<save+ans<<endl;
}
return 0;
}