Cod sursa(job #2022433)

Utilizator lflorin29Florin Laiu lflorin29 Data 16 septembrie 2017 15:51:35
Problema 12-Perm Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>
using namespace std;

const int msk = (1 << 20) - 1;
int n, x[7], y[7], ax[7], ay[7];

int main() {
	ifstream cin("12perm.in");
	ofstream cout("12perm.out");

	cin >> n;
	x[0] = 1;
	x[1] = 1;
	x[2] = 2;
	y[3] = 2;
	x[3] = 4;
	y[4] = 4;
	x[4] = 8;
	int r = 4;
	for(int i = 5; i <= n; ++i) {
		x[5] = x[4] + x[2] + 2;
		y[5] = y[4] + x[3];
		for(int j = 4; j >= 1; --j) {
			ax[j] = x[j + 1];
			ay[j] = y[j + 1];
		}
		for(int j = 4; j >= 1; --j)x[j] = ax[j], y[j] = ay[j];
		x[5] &= msk, y[5] &= msk;
	}
	int ans = x[5] + y[5];
	ans &= msk;
	cout << ans;
}