Cod sursa(job #2068011)

Utilizator osiaccrCristian Osiac osiaccr Data 17 noiembrie 2017 08:17:52
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#define MODO 1 << 20

using namespace std;

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

int n, sol1, sol2, sol3;

int main () {
  fin >> n;

  if (n == 1) {
    fout << 1;
    return 0;
  }
  if (n == 2) {
    fout << 2;
    return 0;
  }
  if (n == 3) {
    fout << 6;
    return 0;
  }
  if (n == 4) {
    fout << 12;
    return 0;
  }

  sol1 = 2;
  sol2 = 6;
  sol3 = 12;

  for (int i = 5; i <= n; ++ i) {
    int aux = (sol3 + sol1 + 2 * (i - 2)) & ((1 << 20) - 1); /// a & ((1 << 20) - 1) este MODO
                                                             /// cand valoarea este numar putere de 2
    sol1 = sol2;
    sol2 = sol3;
    sol3 = aux;
  }

  fout << sol3;

  return 0;
}