Pagini recente » Cod sursa (job #2821881) | Cod sursa (job #1438908) | Cod sursa (job #1439202) | Cod sursa (job #2990811) | Cod sursa (job #1395950)
#include <fstream>
using namespace std;
ifstream fin("12-perm.in");
ofstream fout("12-perm.out");
const int kMax = 15000000;
const int kMod = (1 << 20);
int dp[kMax];
int main()
{
int n; fin >> n;
dp[1] = 1;
dp[2] = 2;
dp[3] = 6;
dp[4] = 12;
for (int i = 5; i <= n; ++i)
dp[i] = (dp[i - 1] + dp[i - 3] + 2 * (i - 2)) & (kMod - 1);
fout << dp[n] << '\n';
return 0;
}