|
| 1 | +/* |
| 2 | + written by Pankaj Kumar. |
| 3 | + country:-INDIA |
| 4 | + Institute: National Institute of Technology, Uttarakhand |
| 5 | +*/ |
| 6 | +#include <bits/stdc++.h> |
| 7 | +#include <ext/pb_ds/assoc_container.hpp> |
| 8 | +#include <ext/pb_ds/tree_policy.hpp> |
| 9 | +using namespace std; |
| 10 | +using namespace __gnu_pbds; |
| 11 | +typedef long long ll ; |
| 12 | +typedef vector<ll> vl; |
| 13 | +typedef vector<vector<ll>> vvl; |
| 14 | +#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0); |
| 15 | +/* Abbrevations */ |
| 16 | +#define ff first |
| 17 | +#define ss second |
| 18 | +#define mp make_pair |
| 19 | +#define line cout<<endl; |
| 20 | +#define pb push_back |
| 21 | +// Some print |
| 22 | +#define no cout<<"NO"<<endl; |
| 23 | +#define yes cout<<"YES"<<endl; |
| 24 | +// sort |
| 25 | +#define all(V) (V).begin(),(V).end() |
| 26 | +#define srt(V) sort(all(V)) |
| 27 | +#define srtGreat(V) sort(all(V),greater<ll>()) |
| 28 | +// some extra |
| 29 | +#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line; |
| 30 | +#define precision(x) cout<<fixed<<setprecision(x); |
| 31 | +#define sz(V) ll(V.size()) |
| 32 | +// datatype definination |
| 33 | +#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> |
| 34 | + |
| 35 | + |
| 36 | +class Codeforces{ |
| 37 | + private: |
| 38 | + // read only variable |
| 39 | + const ll INF=1e18; |
| 40 | + const ll mod1=1e9+7; |
| 41 | + const ll mod2=998244353; |
| 42 | + |
| 43 | + |
| 44 | + public: |
| 45 | + Codeforces(){ |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + ll power(ll x,ll y){ |
| 50 | + ll result=1; |
| 51 | + while(y>0){ |
| 52 | + if(y&1){ |
| 53 | + result*=x; |
| 54 | + } |
| 55 | + y>>=1; |
| 56 | + x*=x; |
| 57 | + } |
| 58 | + return result; |
| 59 | + } |
| 60 | + |
| 61 | + ll power(ll x,ll y,ll mod){ |
| 62 | + ll result=1; |
| 63 | + x%=mod; |
| 64 | + while(y>0){ |
| 65 | + if(y&1){ |
| 66 | + result*=x; |
| 67 | + result%=mod; |
| 68 | + } |
| 69 | + y>>=1; |
| 70 | + x*=x; |
| 71 | + x%=mod; |
| 72 | + } |
| 73 | + return result; |
| 74 | + } |
| 75 | + |
| 76 | + ll str_to_num(string s){ |
| 77 | + stringstream pk(s); |
| 78 | + ll num; |
| 79 | + pk>>num; |
| 80 | + return num; |
| 81 | + } |
| 82 | + |
| 83 | + string num_to_str(ll num){ |
| 84 | + return to_string(num); |
| 85 | + } |
| 86 | + // Techniques : |
| 87 | + // divide into cases, brute force, pattern finding |
| 88 | + // sort, greedy, binary search, two pointer |
| 89 | + // transform into graph |
| 90 | + |
| 91 | + // Experience : |
| 92 | + // Cp is nothing but only observation and mathematics. |
| 93 | + ll solve(){ |
| 94 | + int n; |
| 95 | + cin>>n; |
| 96 | + if(n<=2){ |
| 97 | + cout<<n<<endl; |
| 98 | + } |
| 99 | + else{ |
| 100 | + string s1=""; |
| 101 | + for(int i=0;i<1000;i++){ |
| 102 | + if(i&1){ |
| 103 | + s1+='1'; |
| 104 | + } |
| 105 | + else{ |
| 106 | + s1+='2'; |
| 107 | + } |
| 108 | + } |
| 109 | + int sum=0; |
| 110 | + for(int i=0;i<s1.size();i++){ |
| 111 | + sum+=(s1[i]-'0'); |
| 112 | + if(sum==n){ |
| 113 | + string ans=s1.substr(0,i+1); |
| 114 | + cout<<ans<<endl; |
| 115 | + return 0; |
| 116 | + } |
| 117 | + else if(sum>n){ |
| 118 | + break; |
| 119 | + } |
| 120 | + } |
| 121 | + sum=0; |
| 122 | + for(int i=1;i<sz(s1);i++){ |
| 123 | + sum+=(s1[i]-'0'); |
| 124 | + if(sum==n){ |
| 125 | + string ans=s1.substr(1,i); |
| 126 | + cout<<ans<<endl; |
| 127 | + return 0; |
| 128 | + } |
| 129 | + else if(sum>n){ |
| 130 | + break; |
| 131 | + } |
| 132 | + } |
| 133 | + line; |
| 134 | + } |
| 135 | + return 0; |
| 136 | + } |
| 137 | +}; |
| 138 | + |
| 139 | + |
| 140 | +/* --------------------MAIN PROGRAM----------------------------*/ |
| 141 | + |
| 142 | +int main() |
| 143 | +{ |
| 144 | + speed; |
| 145 | + /* #ifndef ONLINE_JUDGE |
| 146 | + freopen("input.txt","r",stdin); |
| 147 | + freopen("output.txt","w",stdout); |
| 148 | + #endif */ |
| 149 | + ll TestCase=1; |
| 150 | + cin>>TestCase; |
| 151 | + while(TestCase--){ |
| 152 | + Codeforces cf; |
| 153 | + cf.solve(); |
| 154 | + } |
| 155 | +} |
| 156 | +/* -----------------END OF PROGRAM --------------------*/ |
| 157 | +/* |
| 158 | +* stuff you should look before submission |
| 159 | +* constraint and time limit |
| 160 | +* int overflow |
| 161 | +* special test case (n=0||n=1||n=2) |
| 162 | +* don't get stuck on one approach if you get wrong answer |
| 163 | +*/ |
0 commit comments