//biblioteczka z bignumami: //https://github.com/mareksom/acmlib/blob/master/code/blazej/bigNum.cpp #include<stdint.h> #include<bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native") using namespace std; typedef long long lld; #define For(i,s,a) for(lld i = (lld)s; i < (lld)a; ++i) #define FORD(i,s,a) for(long long i = s; i>=a; --i) #define REP(i,a) for(long long i = 0; i<a;++i) #define FOR(i,s,a) for(long long i = s; i<a;++i) #define MP make_pair #define X first #define Y second typedef long long lld; typedef pair<int,int> pii; typedef complex<double> cd; typedef vector<cd> vcd; #define ff first #define dd second #define mp make_pair #define sz size() #define pb push_back using namespace std; vcd fft(const vcd &as) { int n = as.size(); int mp = 0; while ((1 << mp) < n) mp++; vector<int>rev(n); rev[0] = 0; int high = -1; For(i,1,n) { if(!(i & (i-1))) high++; rev[i] = rev[i ^ (1 << high)]; rev[i] |= (1 << (mp-high-1)); } vcd roots(n); For(i,0,n){ double alpha = 2 * M_PI * i / n; roots[i] = cd(cos(alpha), sin(alpha)); } vcd cur(n); For(i,0,n) cur[i] = as[rev[i]]; for(int len = 1; len < n; len <<= 1){ vcd ncur(n); int rstep = roots.size() / (len * 2); for (int pdest = 0; pdest < n;) { int p = pdest; For(i,0,len){ cd val = roots[i * rstep] * cur[p + len]; ncur[pdest] = cur[p] + val; ncur[pdest + len] = cur[p] - val; pdest++, p++; } pdest += len; } cur.swap(ncur); } return cur; } vcd fft_rev(const vcd &as) { vcd res = fft(as); For(i,0,res.sz) res[i] /= as.size(); reverse(res.begin()+1, res.end()); return res; } vcd conj(vcd &a, vcd &b){ int S = a.sz + b.sz; while(__builtin_popcount(S) > 1)S += (S & ( -S )); a.resize(S, 0); b.resize(S, 0); vcd A = fft(a); vcd B = fft(b); For(i,0,A.sz)A[i] *= B[i]; vcd r = fft_rev(A); For(i,0,r.sz)r[i] = cd(((lld)round(r[i].real())),(((lld)round(r[i].imag())))); while(r.sz && round(r.back().real()) == 0)r.pop_back(); return r; } struct bigNum{ typedef uint32_t mult_t; typedef uint16_t base_t; static const base_t BASE = 10000; static const int B_DIGS = 4; static const char prFirst[]; static const char prNext[]; int len, cap; base_t* digs; public: bigNum(): len(0), cap(0), digs(NULL) {} //public: explicit bigNum(base_t n) { len = cap = 2; digs = new base_t[cap]; digs[0] = n % BASE; digs[1] = n / BASE; clen(); } void init(int l, base_t* const d, int c = 0) { len = l; cap = c; if (!c) cap = max(len,1); digs = new base_t[cap]; memcpy(digs, d, len * sizeof(base_t)); memset(digs + len, 0, (cap - len) * sizeof(base_t)); clen(); } void extend(int n_cap) { if (cap >= n_cap) return; base_t* n_digs = new base_t[n_cap]; memcpy(n_digs, digs, len * sizeof(base_t)); memset(n_digs + len, 0, (n_cap - len) * sizeof(base_t)); if(digs) delete[] digs; swap(digs, n_digs); cap = n_cap; } void clen() { while (len > 0 && !digs[len - 1]) --len; } bigNum(int l, base_t* const d, int c = 0) { init(l, d, c); } explicit bigNum(const char* s) { int n = strlen(s); cap = len = (n + B_DIGS - 1) / B_DIGS; digs = new base_t[len]; int pos = 0; FORD(i, len-1, 0) { digs[i] = 0; for (; pos < n - (i) * B_DIGS && pos < n; ++pos) { digs[i] = 10 * digs[i] + s[pos] - '0'; } } clen(); } bigNum(bigNum const & b) { init(b.len, b.digs); } ~bigNum() { if (digs) delete[] digs; } bigNum& operator= (const bigNum & b) { delete[] digs; init(b.len, b.digs); return *this; } bool operator == (bigNum const& b) const { if (len != b.len) return false; REP(i, len) { if (digs[i] != b.digs[i]) return false; } return true; } bool operator != (bigNum const& b) const { return ! (operator==(b)); } short compare(bigNum const& b) const { if (len < b.len) return -1; if (len > b.len) return 1; FORD(i, len - 1, 0) { if (digs[i] < b.digs[i]) return -1; if (digs[i] > b.digs[i]) return 1; } return 0; } bool operator < (bigNum const &b) const { return compare(b) < 0; } bool operator > (bigNum const &b) const { return compare(b) > 0; } bool operator <= (bigNum const &b) const { return compare(b) <= 0; } bool operator >= (bigNum const &b) const { return compare(b) >= 0; } bigNum const& operator += (base_t n) { return operator+=(bigNum(n)); } bigNum const & operator+= (bigNum const& b) { extend(max(len, b.len)+1); len = max(len, b.len)+1; digs[0] += b.digs[0]; int i; for (i = 1; i < len; ++i) { if (digs[i-1] >= BASE) { digs[i-1] -= BASE; ++digs[i]; } else if (i >= b.len) break; if (i<b.len) digs[i] += b.digs[i]; } clen(); return *this; } bigNum const operator+(bigNum const& b) const { bigNum res(len, digs, max(len, b.len) + 1); res += b; return res; } bigNum const& operator -= (bigNum const& b) { base_t rem = 0; REP(i,len) { if (i < b.len) rem += b.digs[i]; if (rem > digs[i]) { digs[i] -= (rem-BASE); rem = 1; } else { digs[i] -= rem; rem = 0; } if (rem == 0 && i >= b.len - 1) break; } assert(rem == 0); clen(); return *this; } bigNum const& operator-= (base_t n) { return operator-=(bigNum(n)); } bigNum const operator- (bigNum const& b) const { bigNum res(len, digs); res -= b; return res; } bigNum const& operator *= (base_t n) { if (n >= BASE) return operator *= (bigNum(n)); extend(len+1); ++len; base_t p = 0; REP(i, len) { mult_t m = (mult_t) digs[i]*n + p; digs[i] = m % BASE; p = m / BASE; } clen(); return *this; } bigNum const operator << (int sh) const { bigNum res; res.extend(len + sh); res.len = len + sh; memcpy(res.digs + sh, digs, len * sizeof(base_t)); return res; } bigNum const multSh(base_t n, int sh) const { assert(n < BASE); bigNum res; res.extend(len + sh + 1); res.len = len + 1 + sh; base_t p = 0; FOR(i, sh, sh + len - 1) { mult_t m = (mult_t) digs[i-sh]*n + p; res.digs[i] = m % BASE; p = m / BASE; } res.digs[len+sh] = p; res.clen(); return res; } bigNum const operator * (bigNum const & b) const { //if(len < 1000 && b.len < 10){ bigNum res; res.extend(len + b.len); REP(i, len) { base_t p = 0; REP(j, b.len) { mult_t m = (mult_t)digs[i] * b.digs[j] + p + res.digs[i+j]; res.digs[i+j] = m%BASE; p = m/BASE; } int s = i + b.len; while (p>0) { res.digs[s] += p; if (res.digs[s] >= BASE) { res.digs[s] -= BASE; p = 1; } else p = 0; } } res.len = len + b.len; res.clen(); return res;//} /*else{ bigNum res; vcd A(len); vcd B(b.len); For(i,0,len) A[i] = cd(digs[i],0); For(i,0,B.sz) B[i] = cd(b.digs[i],0); A = conj(A,B); res.len = A.sz; For(i,0,A.sz)res.digs[i] = round(A[i].real()); return res; }*/ ///rip FFT, dokładność się sypie kind of } bigNum const & operator *= (bigNum const & b) { return *this = *this * b; } base_t operator % (base_t m) const { base_t res = 0; FORD(i, len-1, 0) { res = ((mult_t)BASE*res + digs[i]) % m; } return res; } pair<bigNum, bigNum> const div(bigNum const & b) const { bigNum d; int dlen = max(len - b.len + 1, 0); d.extend(dlen); bigNum rem(*this); FORD(i, dlen-1, 0) { base_t l = 0, r = BASE-1; while (l < r) { base_t m = (l + r + 1) / 2; if (rem < b.multSh(m, i)) { r = m - 1; } else { l = m; } } rem -= b.multSh(l,i); if (l > 0) d.digs[i] = l; } d.len = dlen; d.clen(); return MP(d, rem); } bigNum const sqrt() const { bigNum res; int n = (len + 1) / 2; res.extend(n); bigNum rem(*this); FORD(i, n, 0) { base_t l = 0, r = BASE - 1; while ( l <r) { base_t m = (l+r+1)/2; bigNum b(res); b *= 2; b += (bigNum(m) << i); if (rem < b.multSh(m,i)) { r = m - 1; } else l = m; } bigNum ls = bigNum(l).multSh(1,i); bigNum b(res); b *= 2; b += ls; rem -= b.multSh(l,i); res += ls; if (l != 0 && !res.len) res.len = i + 1; } return res; } bigNum const operator/ (bigNum const & b) const { return div(b).X; } bigNum const operator% (bigNum const & b) const { return div(b).Y; } bigNum const & operator /= (bigNum const &b) { return *this = *this / b; } bigNum const & operator %= (bigNum const &b) { return *this = *this % b; } bigNum const operator /= (base_t n) { if (n >= BASE) return *this/bigNum(n); mult_t p = 0; FORD(i, len-1, 0) { p = BASE*p + digs[i]; digs[i] = p / n; p %= n; } clen(); return *this; } friend std::ostream& operator<< (std::ostream& str, bigNum const &n) { if (n.len == 0) str << 0; else { cout << n.digs[n.len-1]; FORD(i, n.len-2, 0) str << setw(4) << setfill('0') << n.digs[i]; } return str; } friend std::istream& operator>> (std::istream& str, bigNum &n) { string s; str >> s; n = bigNum(s.c_str()); return str; } void write() const { if (len == 0) printf("0"); else { printf(prFirst,digs[len-1]); FORD(i, len-2, 0) printf(prNext,digs[i]); } } void writeln() const { write(); putchar('\n'); } }; const char bigNum::prFirst[] = "%u"; const char bigNum::prNext[] = "%.4u"; const int NN = 100009; bigNum fib[NN]; void solve(){ int n,m; scanf("%d", &n); char a[n]; For(i,0,n)scanf(" %c", &a[i]); scanf("%d", &m); char b[m]; For(i,0,m)scanf(" %c", &b[i]); //cout<<n<<" "<<m<<endl; //printf("%s\n",a); //printf("%s\n",b); bigNum x("0"); bigNum y("0"); bigNum tmp[100]; For(i,0,100)tmp[i] = bigNum("0"); For(i,0,n)if(a[i] == '1') tmp[i%100] += fib[i+1];//fib[i+1].write();// cout<<"a"<<" "<<i<<endl; For(i,0,100) x += tmp[i]; For(i,0,100)tmp[i] = bigNum("0"); For(i,0,m)if(b[i] == '1') tmp[i%100] += fib[i+1];//fib[i+1].write();// cout<<"b"<<" "<<i<<endl; For(i,0,100) y += tmp[i]; x*=y; int cap = n + m + 2; cap = min(cap, NN); char wyn[cap]; int evr = 0; bool pop = 0; for(int i = cap; i + 1; --i){ bool xd = 0; if(pop){pop = 0;} else while(x >= fib[i]){ xd = 1; x-=fib[i]; } wyn[i] = '0' + xd; //x.writeln(); pop = xd; evr = max(evr, i * xd); } printf("%d ",evr); For(i,1,evr+1){putchar_unlocked(wyn[i]), putchar_unlocked(' ');} puts(""); } int main() { /* vcd aa(10,cd(10000)); vcd bb(10, cd(10000)); aa = conj(aa,bb); for(auto s:aa)cout<<(int)round(s.real())<<" "<<(int)round(s.imag())<<endl; */ fib[0] = fib[1] = bigNum("1"); For(i,2,NN){ fib[i] = fib[i-1] + fib[i-2]; } int t; scanf("%d", &t); while(t--){ solve(); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | //biblioteczka z bignumami: //https://github.com/mareksom/acmlib/blob/master/code/blazej/bigNum.cpp #include<stdint.h> #include<bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native") using namespace std; typedef long long lld; #define For(i,s,a) for(lld i = (lld)s; i < (lld)a; ++i) #define FORD(i,s,a) for(long long i = s; i>=a; --i) #define REP(i,a) for(long long i = 0; i<a;++i) #define FOR(i,s,a) for(long long i = s; i<a;++i) #define MP make_pair #define X first #define Y second typedef long long lld; typedef pair<int,int> pii; typedef complex<double> cd; typedef vector<cd> vcd; #define ff first #define dd second #define mp make_pair #define sz size() #define pb push_back using namespace std; vcd fft(const vcd &as) { int n = as.size(); int mp = 0; while ((1 << mp) < n) mp++; vector<int>rev(n); rev[0] = 0; int high = -1; For(i,1,n) { if(!(i & (i-1))) high++; rev[i] = rev[i ^ (1 << high)]; rev[i] |= (1 << (mp-high-1)); } vcd roots(n); For(i,0,n){ double alpha = 2 * M_PI * i / n; roots[i] = cd(cos(alpha), sin(alpha)); } vcd cur(n); For(i,0,n) cur[i] = as[rev[i]]; for(int len = 1; len < n; len <<= 1){ vcd ncur(n); int rstep = roots.size() / (len * 2); for (int pdest = 0; pdest < n;) { int p = pdest; For(i,0,len){ cd val = roots[i * rstep] * cur[p + len]; ncur[pdest] = cur[p] + val; ncur[pdest + len] = cur[p] - val; pdest++, p++; } pdest += len; } cur.swap(ncur); } return cur; } vcd fft_rev(const vcd &as) { vcd res = fft(as); For(i,0,res.sz) res[i] /= as.size(); reverse(res.begin()+1, res.end()); return res; } vcd conj(vcd &a, vcd &b){ int S = a.sz + b.sz; while(__builtin_popcount(S) > 1)S += (S & ( -S )); a.resize(S, 0); b.resize(S, 0); vcd A = fft(a); vcd B = fft(b); For(i,0,A.sz)A[i] *= B[i]; vcd r = fft_rev(A); For(i,0,r.sz)r[i] = cd(((lld)round(r[i].real())),(((lld)round(r[i].imag())))); while(r.sz && round(r.back().real()) == 0)r.pop_back(); return r; } struct bigNum{ typedef uint32_t mult_t; typedef uint16_t base_t; static const base_t BASE = 10000; static const int B_DIGS = 4; static const char prFirst[]; static const char prNext[]; int len, cap; base_t* digs; public: bigNum(): len(0), cap(0), digs(NULL) {} //public: explicit bigNum(base_t n) { len = cap = 2; digs = new base_t[cap]; digs[0] = n % BASE; digs[1] = n / BASE; clen(); } void init(int l, base_t* const d, int c = 0) { len = l; cap = c; if (!c) cap = max(len,1); digs = new base_t[cap]; memcpy(digs, d, len * sizeof(base_t)); memset(digs + len, 0, (cap - len) * sizeof(base_t)); clen(); } void extend(int n_cap) { if (cap >= n_cap) return; base_t* n_digs = new base_t[n_cap]; memcpy(n_digs, digs, len * sizeof(base_t)); memset(n_digs + len, 0, (n_cap - len) * sizeof(base_t)); if(digs) delete[] digs; swap(digs, n_digs); cap = n_cap; } void clen() { while (len > 0 && !digs[len - 1]) --len; } bigNum(int l, base_t* const d, int c = 0) { init(l, d, c); } explicit bigNum(const char* s) { int n = strlen(s); cap = len = (n + B_DIGS - 1) / B_DIGS; digs = new base_t[len]; int pos = 0; FORD(i, len-1, 0) { digs[i] = 0; for (; pos < n - (i) * B_DIGS && pos < n; ++pos) { digs[i] = 10 * digs[i] + s[pos] - '0'; } } clen(); } bigNum(bigNum const & b) { init(b.len, b.digs); } ~bigNum() { if (digs) delete[] digs; } bigNum& operator= (const bigNum & b) { delete[] digs; init(b.len, b.digs); return *this; } bool operator == (bigNum const& b) const { if (len != b.len) return false; REP(i, len) { if (digs[i] != b.digs[i]) return false; } return true; } bool operator != (bigNum const& b) const { return ! (operator==(b)); } short compare(bigNum const& b) const { if (len < b.len) return -1; if (len > b.len) return 1; FORD(i, len - 1, 0) { if (digs[i] < b.digs[i]) return -1; if (digs[i] > b.digs[i]) return 1; } return 0; } bool operator < (bigNum const &b) const { return compare(b) < 0; } bool operator > (bigNum const &b) const { return compare(b) > 0; } bool operator <= (bigNum const &b) const { return compare(b) <= 0; } bool operator >= (bigNum const &b) const { return compare(b) >= 0; } bigNum const& operator += (base_t n) { return operator+=(bigNum(n)); } bigNum const & operator+= (bigNum const& b) { extend(max(len, b.len)+1); len = max(len, b.len)+1; digs[0] += b.digs[0]; int i; for (i = 1; i < len; ++i) { if (digs[i-1] >= BASE) { digs[i-1] -= BASE; ++digs[i]; } else if (i >= b.len) break; if (i<b.len) digs[i] += b.digs[i]; } clen(); return *this; } bigNum const operator+(bigNum const& b) const { bigNum res(len, digs, max(len, b.len) + 1); res += b; return res; } bigNum const& operator -= (bigNum const& b) { base_t rem = 0; REP(i,len) { if (i < b.len) rem += b.digs[i]; if (rem > digs[i]) { digs[i] -= (rem-BASE); rem = 1; } else { digs[i] -= rem; rem = 0; } if (rem == 0 && i >= b.len - 1) break; } assert(rem == 0); clen(); return *this; } bigNum const& operator-= (base_t n) { return operator-=(bigNum(n)); } bigNum const operator- (bigNum const& b) const { bigNum res(len, digs); res -= b; return res; } bigNum const& operator *= (base_t n) { if (n >= BASE) return operator *= (bigNum(n)); extend(len+1); ++len; base_t p = 0; REP(i, len) { mult_t m = (mult_t) digs[i]*n + p; digs[i] = m % BASE; p = m / BASE; } clen(); return *this; } bigNum const operator << (int sh) const { bigNum res; res.extend(len + sh); res.len = len + sh; memcpy(res.digs + sh, digs, len * sizeof(base_t)); return res; } bigNum const multSh(base_t n, int sh) const { assert(n < BASE); bigNum res; res.extend(len + sh + 1); res.len = len + 1 + sh; base_t p = 0; FOR(i, sh, sh + len - 1) { mult_t m = (mult_t) digs[i-sh]*n + p; res.digs[i] = m % BASE; p = m / BASE; } res.digs[len+sh] = p; res.clen(); return res; } bigNum const operator * (bigNum const & b) const { //if(len < 1000 && b.len < 10){ bigNum res; res.extend(len + b.len); REP(i, len) { base_t p = 0; REP(j, b.len) { mult_t m = (mult_t)digs[i] * b.digs[j] + p + res.digs[i+j]; res.digs[i+j] = m%BASE; p = m/BASE; } int s = i + b.len; while (p>0) { res.digs[s] += p; if (res.digs[s] >= BASE) { res.digs[s] -= BASE; p = 1; } else p = 0; } } res.len = len + b.len; res.clen(); return res;//} /*else{ bigNum res; vcd A(len); vcd B(b.len); For(i,0,len) A[i] = cd(digs[i],0); For(i,0,B.sz) B[i] = cd(b.digs[i],0); A = conj(A,B); res.len = A.sz; For(i,0,A.sz)res.digs[i] = round(A[i].real()); return res; }*/ ///rip FFT, dokładność się sypie kind of } bigNum const & operator *= (bigNum const & b) { return *this = *this * b; } base_t operator % (base_t m) const { base_t res = 0; FORD(i, len-1, 0) { res = ((mult_t)BASE*res + digs[i]) % m; } return res; } pair<bigNum, bigNum> const div(bigNum const & b) const { bigNum d; int dlen = max(len - b.len + 1, 0); d.extend(dlen); bigNum rem(*this); FORD(i, dlen-1, 0) { base_t l = 0, r = BASE-1; while (l < r) { base_t m = (l + r + 1) / 2; if (rem < b.multSh(m, i)) { r = m - 1; } else { l = m; } } rem -= b.multSh(l,i); if (l > 0) d.digs[i] = l; } d.len = dlen; d.clen(); return MP(d, rem); } bigNum const sqrt() const { bigNum res; int n = (len + 1) / 2; res.extend(n); bigNum rem(*this); FORD(i, n, 0) { base_t l = 0, r = BASE - 1; while ( l <r) { base_t m = (l+r+1)/2; bigNum b(res); b *= 2; b += (bigNum(m) << i); if (rem < b.multSh(m,i)) { r = m - 1; } else l = m; } bigNum ls = bigNum(l).multSh(1,i); bigNum b(res); b *= 2; b += ls; rem -= b.multSh(l,i); res += ls; if (l != 0 && !res.len) res.len = i + 1; } return res; } bigNum const operator/ (bigNum const & b) const { return div(b).X; } bigNum const operator% (bigNum const & b) const { return div(b).Y; } bigNum const & operator /= (bigNum const &b) { return *this = *this / b; } bigNum const & operator %= (bigNum const &b) { return *this = *this % b; } bigNum const operator /= (base_t n) { if (n >= BASE) return *this/bigNum(n); mult_t p = 0; FORD(i, len-1, 0) { p = BASE*p + digs[i]; digs[i] = p / n; p %= n; } clen(); return *this; } friend std::ostream& operator<< (std::ostream& str, bigNum const &n) { if (n.len == 0) str << 0; else { cout << n.digs[n.len-1]; FORD(i, n.len-2, 0) str << setw(4) << setfill('0') << n.digs[i]; } return str; } friend std::istream& operator>> (std::istream& str, bigNum &n) { string s; str >> s; n = bigNum(s.c_str()); return str; } void write() const { if (len == 0) printf("0"); else { printf(prFirst,digs[len-1]); FORD(i, len-2, 0) printf(prNext,digs[i]); } } void writeln() const { write(); putchar('\n'); } }; const char bigNum::prFirst[] = "%u"; const char bigNum::prNext[] = "%.4u"; const int NN = 100009; bigNum fib[NN]; void solve(){ int n,m; scanf("%d", &n); char a[n]; For(i,0,n)scanf(" %c", &a[i]); scanf("%d", &m); char b[m]; For(i,0,m)scanf(" %c", &b[i]); //cout<<n<<" "<<m<<endl; //printf("%s\n",a); //printf("%s\n",b); bigNum x("0"); bigNum y("0"); bigNum tmp[100]; For(i,0,100)tmp[i] = bigNum("0"); For(i,0,n)if(a[i] == '1') tmp[i%100] += fib[i+1];//fib[i+1].write();// cout<<"a"<<" "<<i<<endl; For(i,0,100) x += tmp[i]; For(i,0,100)tmp[i] = bigNum("0"); For(i,0,m)if(b[i] == '1') tmp[i%100] += fib[i+1];//fib[i+1].write();// cout<<"b"<<" "<<i<<endl; For(i,0,100) y += tmp[i]; x*=y; int cap = n + m + 2; cap = min(cap, NN); char wyn[cap]; int evr = 0; bool pop = 0; for(int i = cap; i + 1; --i){ bool xd = 0; if(pop){pop = 0;} else while(x >= fib[i]){ xd = 1; x-=fib[i]; } wyn[i] = '0' + xd; //x.writeln(); pop = xd; evr = max(evr, i * xd); } printf("%d ",evr); For(i,1,evr+1){putchar_unlocked(wyn[i]), putchar_unlocked(' ');} puts(""); } int main() { /* vcd aa(10,cd(10000)); vcd bb(10, cd(10000)); aa = conj(aa,bb); for(auto s:aa)cout<<(int)round(s.real())<<" "<<(int)round(s.imag())<<endl; */ fib[0] = fib[1] = bigNum("1"); For(i,2,NN){ fib[i] = fib[i-1] + fib[i-2]; } int t; scanf("%d", &t); while(t--){ solve(); } } |