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:
- 3371–33–3–77–3371_33_3_77_ (you can remove the second and fifth characters);
- 3371–3–33–77–3371_3_33_77_ (you can remove the third and fifth characters);
- 3371–3–3–377–3371_3_3_377_ (you can remove the fourth and fifth characters);
- 3371–33–3–7–73371_33_3_7_7 (you can remove the second and sixth characters);
- 3371–3–33–7–73371_3_33_7_7 (you can remove the third and sixth characters);
- 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;
}
}