URL: http://codeforces.com/problemset/problem/1202/D
Meaning of the questions:
$ $ A n-input, the output contains only a $ 1,3,7 $ string, the string has a sequence $ $ $ 1337 $ n-length does not exceed $ 1e5 $.
answer:
First, we know that $ C_ {2} ^ {n} = \ frac {n (n-1)} {2} $ so if it satisfies $ n = \ frac {x (x-1)} {2} $ a, $ 133 $ 3337 ..... output (containing a $ X $ $ $ 3) to. This is obvious. Then, if it is not satisfied. Really I can not think when this race, behind wanted to clear up. First, because they no longer meet the $ n = \ frac {x (x-1)} {2} $, we have found from recent and less than $ $ $ n-n-$ a $ \ frac {x (x-1)} {2} $ calculated $ rem = n- \ frac {x (x-1)} {2} $, $ 13,377 and construction string ...... ..... 7733 $ 337 (containing a $ $ $ REM 7 $ and $ k $ a $ 3 $). The $ k $ how it should be calculated? Sequences and the front configuration comprising $ REM $ subsequences, then the back-containing $ C_ {k} ^ {2} $ in front and rear depicting a $ 3 $ are $ 2 \ cdot k $ a, and then combined with the foregoing $ 133 $ and final $ 7 $, $ 1 from $ a, so $ n = n- \ frac {x (x-1)} {2} + C_ {k} ^ {2} +2 \ cdot k + 1 $ a, because $ n, x $ known, calculated $ k $.
AC Code:
#include <bits/stdc++.h> using namespace std; long long num[100005]; void init() { for(long long i=1;i<100005;++i) num[i]=i*(i-1)/2; } int main() { init(); int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int pos; for(pos=1;num[pos]<=n;++pos); pos-=1; if(n-num[pos]) { cout<<"133"; for(int i=0;i<n-num[pos];++i) cout<<'7'; for(int i=0;i<pos-2;++i) cout<< '3'; cout<<'7'; cout<<endl; } else { cout<<'1'; for(int i=0;i<pos;++i) cout<<'3'; cout<<'7'; cout<<endl; } } return 0; }