Pagini recente » Cod sursa (job #2979310) | Cod sursa (job #2726317) | Cod sursa (job #2786371) | Cod sursa (job #146288) | Cod sursa (job #3296992)
#include <stdio.h>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <numeric>
using uint = unsigned;
constexpr uint MASK = 1048576 - 1;
int main() {
FILE *fin = fopen( "12perm.in", "r" );
FILE *fout = fopen( "12perm.out", "w" );
int n;
fscanf( fin, "%d", &n );
if( n <= 3 ){
int fact[3 + 1] = { 1, 1, 2, 6 };
fprintf( fout, "%d\n", fact[n] );
fclose( fin );
fclose( fout );
return 0;
}
std::vector<uint> tail({ 1, 1, 1, 2 });
for( int i = (int)tail.size(); i <= n; i++ )
tail.push_back( tail[i - 1] + tail[i - 3] + 1 );
uint ret = (n % 2) * 2 + 2 * tail[n];
for( int poz_max = 1; 2 * poz_max + 1 < n; poz_max++ ){
uint cnt_poz_max = 0;
cnt_poz_max += tail[n - 2 * poz_max];
cnt_poz_max += tail[n - 2 * poz_max - 1];
ret += 2 * cnt_poz_max;
}
fprintf( fout, "%d\n", int(ret & MASK) );
fclose( fin );
fclose( fout );
return 0;
}