题目链接:https://codeforces.com/problemset/problem/1202/D

 


 

题意:

构造一串只由 ‘1’,‘3’,‘7’ 组成的字符串,使其 ‘1337’ 子序列数量为n

 

思路:

 构造 ‘13377733337’ 类型的字符串,使 C(m,2)+k=n

k为中间 ‘7’ 的数量,C(m,2)为中间 ‘3’ 的数量

 

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 #define rep(i,m,n) for(int i=m;i<n;i++) 
 5 const int N = 2e5+5;
 6 ll a[100006],b[100006];
 7 
 8 int main(){
 9     ios::sync_with_stdio(false);
10     cin.tie(0);
11     cout.tie(0);
12     int t,n;
13     cin>>t;
14     while(t--){
15         cin>>n;
16         int num=sqrt(n*2),x,y;
17         rep(i,num,2*n+1){
18             if(i*(i-1)<=2*n)
19                 x=i,y=n-i*(i-1)/2;
20             else
21                 break;
22         }
23         cout<<"133";
24         rep(i,0,y)
25             cout<<"7";
26         rep(i,0,x-2)
27             cout<<"3";
28         cout<<"7"<<endl;
29     }
30     return 0;
31 }