1. 程式人生 > >3-palindrome CodeForces - 805B (思維)

3-palindrome CodeForces - 805B (思維)

In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.

He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

Input

The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.

Output

Print the string that satisfies all the constraints.

If there are multiple answers, print any of them.

Examples

Input
2
Output
aa
Input
3
Output
bba

Note

palindrome is a sequence of characters which reads the same backward and forward.

 

題意:給你一個整數N,讓你輸出一個字串,只包括abc三個字串,並且它的所有長度為3的子串不能使迴文串,並且c字元要求儘可能的少。

 

思路:既然要求c字元出現的儘可能的少,那麼設想下是否可以不用c字元來構造出這個字串。

通過思考可以發現,僅用兩個字元ab,可以通過連續兩個相同的字元來構造出整個字串

即aabb,aabbaa,aabba,aab,aabbaabb,這樣的。並且一定符合條件。

我們只需要用程式碼實現出來就好了。

我的AC程式碼:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    ll l,r;
    cin>>l>>r;
    if(l==r)
    {
        cout<<l<<endl;
    }else
    {
        if(r-l>=2)
        {
            cout<<2<<endl;
        }else
        {
            cout<<l<<endl;
        }
    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}