fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<int> thr(int x)
  4. {
  5. vector <int>v,vv;
  6. while(x)
  7. {
  8. if(x%3>1)
  9. {
  10. vv.push_back(-1);
  11. return vv;
  12. }
  13. v.push_back(x%3);
  14. x/=3;
  15. }
  16. return v;
  17. }
  18. int main() {
  19. int t;
  20. cin>>t;
  21. while(t--)
  22. {
  23. int x;
  24. long long y=0;
  25. cin>>x;
  26. vector<int> v2=thr(x);
  27. for(int i=0;i<v2.size();i++)
  28. {
  29. y+=v2[i]*pow(2,i);
  30. }
  31.  
  32. cout<<y;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5380KB
stdin
4
10
13
36
5
stdout
5712-1