Pagini recente » Cod sursa (job #2686394) | Cod sursa (job #249592) | Cod sursa (job #2960824) | Cod sursa (job #803611) | Cod sursa (job #1846778)
#include<fstream>
#include<vector>
#include<string>
#define modo 2000003
using namespace std;
const long long int P = 2000003;
ifstream fin("sandokan.in");
ofstream fout("sandokan.out");
int i, j,contor,st,dr,solution,x,y,m, p;
long long int n, k;
long long power(long long int baza, long long int exponent)
{
long long x;
if(exponent == 0) return 1;
else
{
if(exponent % 2 == 1)
{
x = power(baza ,exponent / 2);
return ((x*x)%modo*baza)%modo;
}
else
{
x = power(baza, exponent/2);
return (x*x)%modo;
}
}
}
long long int factorial (int n)
{
long long int rez = 1;
for(i = 2; i <= n; i++)
{
rez = (rez * i) % P;
}
return rez;
}
int main()
{
fin >> n >> p;
k = (((n % (p - 1)) - 1) + p) % p;
//fout << k <<"\n";
n--;
long long int solution = 1, value = 1;
solution = factorial(n);
value = factorial(k);
solution = (solution * power(value, P - 2)) % P;
value = factorial(n - k);
solution = (solution * power(value, P - 2)) % P;
fout << solution << "\n";
}