Cod sursa(job #25440)

Utilizator StTwisterKerekes Felix StTwister Data 4 martie 2007 12:36:51
Problema Kperm Scor 20
Compilator cpp Status done
Runda preONI 2007, Runda 3, Clasele 11-12 Marime 1.12 kb
#include <stdio.h>

#define MOD 666013

int N,K;

int A[] = {1, 2, 0, 6, 0, 6, 24, 0, 4, 0, 120, 0, 8, 0, 120, 720, 0, 48, 0, 48, 0, 5040, 0, 48, 0, 48, 0, 5040, 40320, 0, 144, 0, 96, 0, 1440, 0, 362880, 0, 1296, 0, 384, 0, 960, 0, 362880, 298735, 0, 1728, 0, 3840, 0, 1152, 0, 80640, 0, 622033, 0, 6912, 0, 2304, 0, 2304, 0, 40320, 0, 622033, 138253, 0, 82944, 0, 3456, 0, 7680, 0, 34560, 0, 597470, 0, 465263, 0, 138240, 0, 10368, 0, 46080, 0, 46080, 0, 238988, 0, 465263, 519565, 0, 25187, 0, 62208, 0, 645120, 0, 92160, 0};

int main()
{
    freopen("kperm.in", "r", stdin);
    freopen("kperm.out", "w", stdout);


    scanf("%d %d", &N, &K);

    if (K%2 == 0)
        printf("0\n");
    else
    {
        if (K != 1)
        {
            int off = N-1;
            off = off*(off+1)/2;
            off += K;
            --off;
            printf("%d\n", A[off]);
        }
        else
        {
            int fac = 1;
            for (int i = 2; i<=N; ++i)
            {
                fac *= i;
                fac %= MOD;
            }
            printf("%d\n", fac);
        }
    }
}