Codeforces Round #777 (Div. 2) A. Madoka and Math Dad

A. Madoka and Math Dad

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Madoka finally found the administrator password for her computer. Her father is a well-known popularizer of mathematics, so the password is the answer to the following problem.

Find the maximum decimal number without zeroes and with no equal digits in a row, such that the sum of its digits is nn.

Madoka is too tired of math to solve it herself, so help her to solve this problem!

Input

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Description of the test cases follows.

The only line of each test case contains an integer nn (1≤n≤10001≤n≤1000) — the required sum of the digits.

Output

For each test case print the maximum number you can obtain.

Example

input

Copy

5
1
2
3
4
5

output

Copy

1
2
21
121
212

Note

The only numbers with the sum of digits equal to 22 without zeros are 22 and 1111. But the last one has two ones in a row, so it's not valid. That's why the answer is 22.

The only numbers with the sum of digits equal to 33 without zeros are 111111, 1212, 2121, and 33. The first one has 22 ones in a row, so it's not valid. So the maximum valid number is 2121.

The only numbers with the sum of digits equals to 44 without zeros are 11111111, 211211, 121121, 112112, 1313, 3131, 2222, and 44. Numbers 11111111, 211211, 112112, 2222 aren't valid, because they have some identical digits in a row. So the maximum valid number is 121121.

代码如下:

#include<iostream>
using namespace std;

int t;

void solve(int n) {
    if(n < 3)
        cout << n << "\n";
    else if(n % 3 == 0) {
        for (int i = 0; i < n / 3; i ++)
            cout << 21;
        cout << "\n";
    }
    else if(n % 3 == 2) {
        for (int i = 0; i < n / 3; i ++)
            cout << 21;
        cout << 2 << "\n";
    }
    else if(n % 3 == 1) {
        cout << 1;
        for (int i = 0; i < n / 3; i ++)
            cout << 21;
        cout << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(nullptr);

    cin >> t;

    int n;
    for (int i = 0; i < t; i ++) {
        cin >> n;
        solve(n);
    }

        return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值