#include #include #include #include using namespace std; // the ultimate cute solution // it's trivial to prove that, if a solution exists, this will find it #ifdef _MSC_VER typedef unsigned __int64 uint64_t; #endif void process(string s) { cout << s << " = "; char *end; uint64_t r = strtoul(s.c_str(), &end, 10); uint64_t w = 1; while(r) { uint64_t n=w*3; if(r%n == 0) cout << "N"; else if((r+w)%n == 0) { cout << "L"; r+=w; } else if((r-w)%n == 0) { cout << "R"; r-=w; } else cout << "B"; // B for barf w=n; } cout << endl; } int main() { while(cin) { string s; cin >> s; if(s.empty()) continue; process(s); } return 0; }