https://www.acmicpc.net/problem/1740
n을 이진수로 표현한 후, 3의 거듭제곱을 더해주면 된다.
ex. 1) n = 4
n -> 100
ans = 3^2
ex. 2) n = 9
n -> 1001
ans = 3^3 + 3^0
#include <iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
long long n, ans=0;
cin >> n;
long long power=1;
while(n) {
if(n & 1) ans += power;
power *= 3;
n >>= 1;
}
cout << ans;
return 0;
}