赛时最后5分钟才想明白三进制做法,没时间写了
求下面这个程序的hack,20pts AC on #4 #5
#include <cstdio>
using namespace std;
typedef long long ll;
int T;
ll solve(ll _x)
{
if (_x == 1) return 2;
else if (_x == 2) return 1;
else if (_x == 3) return 2;
if (_x % 3 == 0) return solve(_x/3);
else if (_x % 3 == 1) return 2 * solve((_x-1)/3);
else return solve((_x-2)/3);
}
//电脑看不见
int main()
{
scanf("%d", &T);
while (T--)
{
ll x;
scanf("%lld", &x);
if (x % 3 == 2 || x == 0) printf("0\n");
else if (x == 1) printf("1\n");
else
{
//if (x % 3 == 0) x /= 3;
while (x % 3 != 0) x--;
printf("%lld\n", solve(x));
}
}
return 0;
}