根据题目的说明,一种是2x + 1,一种是2x + 2,很明显,第一个生成奇数,第二个生成偶数。 我们根据题目所给的数进行逆推即可。 如果当前的数是奇数,说明它是由于第一种操作得到的,所以我们进行第一个操作的逆操作。 偶数以此类推,最后把得到的答案反转或者倒序输出即可。

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    
    int n;
    cin >> n;
    
    string s = "";
    
    int ans = 0;
    while(true) {
        if(n == 0) {
            break;
        }
        
        if(n & 1) {
            s += 'N';
            n -= 1;
            n /= 2;
        } else {
            s += 'G';
            n -= 2;
            n /= 2;
        }
        
    }
    
    reverse(s.begin(), s.end());
    
    cout << s;
    
    return 0;
}