Cod sursa(job #169100)

Utilizator stefynr8Space Monkey stefynr8 Data 1 aprilie 2008 02:09:06
Problema Sandokan Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream.h>
#include <fstream.h>
#include <math.h>



int main()

{
 fstream f1("sandokan.in",ios::in);
 fstream f2("sandokan.out",ios::out);
 int n,k,rest,i;
 long max,kfc,nfc,restfc;
 
 max=0;
 
 f1 >> n;
 f1 >> k;
 
 rest=n%(k-1);
 if (!rest) rest=k-1;
 rest--;
 n--;
 k=n-rest;
 kfc=1;
 nfc=1;
 restfc=1;
 
 for (i=1;i<=rest;i++) restfc=restfc*i%2000003; 
 for (i=1;i<=k;i++) kfc=kfc*i%2000003;
 nfc=kfc;
 for (i=k+1;i<=n;i++) nfc=nfc*i%2000003;
 
 max=(nfc/kfc)/restfc%2000003;

 //cout << n <<" "<< nfc <<"\n"<< rest <<" "<< restfc <<"\n"<< k <<" "<< kfc <<"\n"<< max;
 //getchar(); 
 f2 << max;
 f1.close();
 f2.close();
 
 return 0;
}