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 n.
You have to find a sequence s consisting of digits {1,3,7} such that it has exactly n subsequences equal to 1337.
For example, sequence 337133377 has 6 subsequences equal to 1337:
3371–33–3–77– (you can remove the second and fifth characters);
3371–3–33–77– (you can remove the third and fifth characters);
3371–3–3–377– (you can remove the fourth and fifth characters);
3371–33–3–7–7 (you can remove the second and sixth characters);
3371–3–33–7–7 (you can remove the third and sixth characters);
3371–3–3–37–7 (you can remove the fourth and sixth characters).
Note that the length of the sequence s must not exceed 105.
You have to answer t independent queries.
Input
The first line contains one integer t (1≤t≤10) — the number of queries.
Next t lines contains a description of queries: the i-th line contains one integer ni (1≤ni≤109).
Output
For the i-th query print one string si (1≤|si|≤105) consisting of digits {1,3,7}. String si must have exactly ni subsequences 1337. If there are multiple such strings, print any of them.
Example
Input
2
6
1
Output
113337
1337
将答案分解成133 7777(若干个7)33333(若干个3) 7 33333(若干个3)7
第一个1和最后一个7加上中间所有的3(假设有i1个3)组成的1337个数为i1*(i1-1)/2;
第一个1和中间的7加上两者之间的3(假设有i2个3)组成的1337个数为i2*(i2-1)/2;
剩下再用 n-i1*(i1-1)/2-i2*(i2-1)/2 个7放在最开始的133后面解决剩下的次数。
#include<stdio.h>
#include<math.h>
int n,t;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int i1;
int maxn=1+sqrt(2*n);
int tmp;
for(i1=maxn;i1>1;i1--)
{
tmp=i1*(i1-1)/2;
if(n>=tmp)
break;
}
if(i1>1)
n-=i1*(i1-1)/2;
int i2;
maxn=1+sqrt(2*n);
for(i2=maxn;i2>1;i2--)
{
tmp=i2*(i2-1)/2;
if(n>=tmp)
break;
}
if(i2>1)
n-=i2*(i2-1)/2;
printf("133");
for(int i=1;i<=n;i++)
printf("7");
if(i2>1)
{
for(int i=1;i<=i2-2;i++)
printf("3");
printf("7");
}
for(int i=1;i<=i1-i2&&i<=i1-2;i++)
printf("3");
printf("7\n");
}
}