Cod sursa(job #2187354)

Utilizator NToniBoSSNicolae Tonitza NToniBoSS Data 26 martie 2018 13:54:19
Problema Sandokan Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#define MOD 2000003
#define LIM 1<<17
/// TONI BO$$ was here
/// #MLC

using namespace std;
char BUF[LIM];
int poz,fact[5001];

inline char getChar(){
    poz++;
    if(poz>=LIM){
    	fread(BUF,LIM,1,stdin);
    	poz=0;
    }
    return BUF[poz];
}

inline int getNr(){
    int r=0, semn=1;
    char ch=getChar();
    while(isdigit(ch)==0 && ch!='-') ch=getChar();
    if(ch=='-'){
        semn=-1;
        ch=getChar();
    }
    while(isdigit(ch)!=0){
        r=r*10+semn*(ch-'0');
        ch=getChar();
    }
    return r;
}

long long lgput(int a,int b)
{
    long long p=1LL;
    while(b)
    {
        if(b%2)
            p=(p*a)%MOD;
        a=(1LL*a*a)%MOD;
        b/=2;
    }
    return p;

}

int main()
{
    int i,n,k;
    long long rez;
    freopen("sandokan.in","r",stdin);
    freopen("sandokan.out","w",stdout);
    n=getNr();
    k=getNr();
    if(n%(k-1)) k=n%(k-1);
    else k--;
    fact[0]=1;
    for(i=1; i<=5000; i++)
        fact[i]=(1LL*fact[i-1]*i)%MOD;
    rez=fact[n-1];
    rez=rez*1LL*lgput(fact[k-1],MOD-2)%MOD;
    rez=rez*1LL*lgput(fact[n-k],MOD-2)%MOD;
    printf("%lld",rez);

    return 0;
}