# [Mathematics & & Law] hacker rank XOR matrix

Problem Description

Here's your first sequence. This sequence has n numbers.
Suppose the first sequence is a0, a1, a2 an.
Then the second sequence is a0^a1, a1^a2, a2^a3 , an^a0.
Ask you what the value of the m-th sequence is
For example:
4 2
6 7 1 3
The first sequence is 67 1 3
The second sequence is 1 6 2 5
The third sequence is 7 4 7 4
and so on.
The example asks you for a second sequence. So sample output: 1 6 2 5

Ideas:

Xiangyu is huge. I can't think how to find the law. So give me an AC code, with a code for typing

```#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100055;
ll a[N], b[N];
int main()
{
int n;
ll m;
while(cin >> n >> m)
{
for(int i = 0; i < n; i++)
cin >> a[i];
m--;
ll x = 1;
while(m)
{
if(m&1)
{
for(int i = 0; i < n; i++)
b[i] = a[i]^a[(i+x)%n];
memcpy(a, b, sizeof(b));
}
m >>= 1;
x <<= 1;
}
for(int i = 0; i < n; i++)
{
cout << a[i];
if(i == n-1) printf("\n");
else printf(" ");
}
}
return 0;
}
//#include<bits/stdc++.h>
//using namespace std;
//vector<int> a[10000], b[10000];
//int main()
//{
//    int n, m, num;
//    while(~scanf("%d %d", &n, &m))
//    {
//        for(int i = 0; i < n; i++)
//        {
//            scanf("%d", &num);
//            a[i].push_back(num);
//            b[i].push_back(num);
//        }
//        int flag = 0;
//        for(;flag < 50; flag++)
//        {
//            for(int i = 0; i < n; i++)
//            {
//                for(int j = 0; j < a[(i+1)%n].size(); j++)
//                {
//                    b[i].push_back(a[(i+1)%n][j]);
//                }
//                sort(b[i].begin(), b[i].end());
//                int t = b[i].size();
//                for(int j = 0; j < t - 1; j++)
//                {
//                    if(b[i][j] == b[i][j+1])
//                    {
//
//                        b[i].erase(b[i].begin() + j);
//                        b[i].erase(b[i].begin() + j);
//                        j--;
//                        t -= 2;
//                    }
//                }
//            }
//            for(int i = 0; i < n; i++)
//            {
//                a[i].assign(b[i].begin(), b[i].end());
//            }
//            printf("hang = %d ", flag+2);
//            for(int i = 0; i < n; i++)
//            {
//                for(int j = 0; j < a[i].size(); j++)
//                {
//                    printf("%d", a[i][j]);
//                }
//                printf(" ");
//            }
//            printf("\n");
//        }
//    }
//    return 0;
//}
```

Added by TheMoose on Sat, 02 May 2020 09:25:33 +0300