#include #include #include using namespace std; ifstream fin("radix3.txt"); #define cin fin char *gsc(long long n) { static char buf[100]; if (n == 0) { sprintf(buf, "0"); } else { bool negative = (n < 0); if (negative) n *= -1; char hoge[100]; int index = 0; while (n != 0) { if (n % 3 == 1) { hoge[index] = '1'; n--; } else if (n % 3 == 2) { hoge[index] = '-'; n++; } else { hoge[index] = '0'; } n /= 3; index++; } for (int i = 0; i < index; i++) buf[i] = hoge[index-1-i]; if (negative) { for (int i = 0; i < index; i++) { if (buf[i] == '1') buf[i] = '-'; else if (buf[i] == '-') buf[i] = '1'; } } buf[index] = '\0'; } return buf; } int main() { int n; while (cin >> n) cout << n << " = " << gsc(n) << " GSC" << endl; return 0; }