Cod sursa(job #2335720)

Utilizator Cristi_SimaSimache Cristian Cristi_Sima Data 4 februarie 2019 14:34:58
Problema Kperm Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#define LIM 666013
using namespace std;
ifstream in("kperm.in");
ofstream out("kperm.out");
int fact(int n)
{
    long long R=1;
    for(int i=2;i<=n;i++)   R=(R*i)%LIM;
    return R;
}
int pow(long long b,int e)
{
    long long R=1;
    while(e)
    {
        if(e&1) R=(R*b)%LIM;
        b=(b*b)%LIM;    e>>=1;
    }
    return R;
}
int main()
{
    int n,k,r;
    in>>n>>k;
    r=n%k;
    long long p1=pow(fact(n/k)  ,k-r);
    long long p2=pow(fact(n/k+1),r  );
    long long p3=fact(r);
    long long p4=fact(k-r);
    long long R=(((((p1*p2)%LIM)*p3)%LIM)*p4)%LIM;
    if(k%2==0 && k%4!=0)    out<<0;
    else    out<<R;
}