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
#include<iostream>
#include<vector>
using namespace std;
int fib[1000000];
int main(){
    int t;
    cin >> t;
    fib[0] = 1;
    fib[1] = 2;
    int p = 1;
    while(fib[p] <= 1000001){
        p++;
        fib[p] = fib[p-1] + fib[p-2];
    }
    for(int i = 0; i < t; i++){
        vector<int> tab = {};
        int n;
        cin >> n;
        int licz1 = 0;
        for(int j = 0; j < n; j++){
            int y;
            cin >> y;
            licz1 += fib[j] * y;
        }
        cin >> n;
        int licz2 = 0;
        for(int j = 0; j < n; j++){
            int y;
            cin >> y;
            licz2 += fib[j] * y;
        }
        licz1 *= licz2;
        int maxi = 0;
        for(int j = 0; j < 100000000; j++){
            if(fib[j] > licz1){
                maxi = j-1;
                break;
            }
        }
        for(int j = maxi; j >=0; j--){
            if(licz1 / fib[j] == 1){
                tab.push_back(1);
                 licz1 = licz1 % fib[j];
            } else{
                tab.push_back(0);
            }
        }
        cout << tab.size() << " ";
        for(int j = tab.size()-1;j >= 0; j--){
            cout << tab[j] << " ";
        }
        cout << endl;
    }
}