Cod sursa(job #3131785)

Utilizator AlexSerban21Serban Alexandru AlexSerban21 Data 21 mai 2023 14:17:29
Problema Sandokan Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>
using namespace std;
ifstream fin ("sandokan.in");
ofstream fout ("sandokan.out");
int n,k,p,i,j,a[5002],b[5002];
int main()
{
    fin>>n>>k;
    p=n;
    while (p>=k)
        p=p-k+1;
    a[0]=1;
    for (i=1; i<n; i++)
    {
        b[0]=1;
        for (j=1; j<=i; j++)
            b[j]=(a[j]+a[j-1])%2000003;
        for (j=0; j<=i; j++)
            a[j]=b[j];
    }
    fout<<a[p-1];
    return 0;
}