Cod sursa(job #2193175)

Utilizator lucametehauDart Monkey lucametehau Data 9 aprilie 2018 10:03:24
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>
#include <cmath>

using namespace std;

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

const int mod = (1 << 20);

int n;

int dp[5];

int main() {
  cin >> n;
  dp[1] = 1;
  dp[2] = 2;
  dp[3] = 6;
  dp[4] = 12;
  for(int i = 5; i <= n; i++) {
    dp[5] = (dp[4] + dp[2] + 2 * (i - 2)) % mod;
    dp[1] = dp[2];
    dp[2] = dp[3];
    dp[3] = dp[4];
    dp[4] = dp[5];
  }
  cout << dp[5];
  return 0;
}