Cod sursa(job #865665)

Utilizator stoicatheoFlirk Navok stoicatheo Data 26 ianuarie 2013 20:06:13
Problema Kperm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <stdio.h>
#define MOD 666013
 
int fact(int x)
{
    int i, ans = 1;
 
    for (i = 2; i <= x; i ++)
        ans = 1LL * ans * i % MOD;
 
    return ans;
}
 
int pw(int A, int B)
{
    int times, ans = 1;
 
    for (times = 1; times <= B; times ++)
        ans = ans * 1LL * A % MOD;
    return ans;
}
 
int main()
{
    int K, N;
 
    freopen("kperm.in", "r", stdin);
    freopen("kperm.out", "w", stdout);
 
    scanf("%d%d", &N, &K);
    if (K % 2 == 0)
    {
        printf("0");
        return 0;
    }
 
    int C = N / K, R = N % K;
    int sol = 1LL * fact(R) * pw(fact(C + 1) % MOD, R) % MOD;
    sol = (sol * 1LL * fact(K - R)) % MOD;
    sol = sol * 1LL * pw(fact(C) % MOD, K - R) % MOD;
 
    printf("%d", sol);
    return 0;
}