codeforces 1202D 1337

10 篇文章 0 订阅

题目

D. Print a 1337-string...

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You are given an integer nn.

You have to find a sequence ss consisting of digits {1,3,7}{1,3,7} such that it has exactly nn subsequences equal to 13371337.

For example, sequence 337133377337133377 has 66 subsequences equal to 13371337:

  1. 3371–33–3–77–3371_33_3_77_ (you can remove the second and fifth characters);
  2. 3371–3–33–77–3371_3_33_77_ (you can remove the third and fifth characters);
  3. 3371–3–3–377–3371_3_3_377_ (you can remove the fourth and fifth characters);
  4. 3371–33–3–7–73371_33_3_7_7 (you can remove the second and sixth characters);
  5. 3371–3–33–7–73371_3_33_7_7 (you can remove the third and sixth characters);
  6. 3371–3–3–37–73371_3_3_37_7 (you can remove the fourth and sixth characters).

Note that the length of the sequence ss must not exceed 105105.

You have to answer tt independent queries.

Input

The first line contains one integer tt (1≤t≤101≤t≤10) — the number of queries.

Next tt lines contains a description of queries: the ii-th line contains one integer nini (1≤ni≤1091≤ni≤109).

Output

For the ii-th query print one string sisi (1≤|si|≤1051≤|si|≤105) consisting of digits {1,3,7}{1,3,7}. String sisi must have exactly nini subsequences 13371337. If there are multiple such strings, print any of them.

Example

input

Copy

2
6
1

output

Copy

113337
1337

一组由1,3,7组成的字符串可以随便删除数据最后只剩1337 问能做成多少个1337.一开始用的是直接暴力输出结果超时了才发现有字符串长度限制。

思路 可以以三为界限算出三最多出现几次然后用1来补足C(n,2)的次数。

#include<string.h>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#define ll long long
using namespace std;
const int N=1000010;
int hea[N][27],tot=0,en[N];

int main()
{
    ll n,a=1,t;
    cin>>t;
    while(t--)
    {
        a=0;

        cin>>n;
        while(a*(a+1)/2<=n)
            a++;
        //cout<<a<<endl;
        cout<<1;
        for(int i=1; i<=a-2; i++)
            cout<<3;
        for(int i=1; i<=n-a*(a-1)/2; i++)
        {
            cout<<1;
        }
        cout<<337<<endl;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值