Cod sursa(job #1752362)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 3 septembrie 2016 16:50:46
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

ifstream fin("12perm.in");
ofstream fout("12perm.out");

int main() {

	const int mask = (1 << 20) - 1;
	int n; fin >> n;

	int a1 = 2;
	int a2 = 6;
	int a3 = 12;

	switch (n) {
		case 1: fout << "1\n"; return 0;
		case 2: fout << a1 << '\n'; return 0;
		case 3: fout << a2 << '\n'; return 0;
		case 4: fout << a3 << '\n'; return 0;
	}

	for (int i = 5; i <= n; ++i) {

		int a = a1 + a3 + 2 * (i - 2);
		a &= mask;

		a1 = a2, a2 = a3, a3 = a;

	}

	fout << a3 << '\n';

	return 0;

}

//Trust me, I'm the Doctor!