Pagini recente » Cod sursa (job #2334589) | Cod sursa (job #2074737) | Cod sursa (job #323638) | Cod sursa (job #1808807) | Cod sursa (job #1846789)
#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;
int k = n % (p - 1);
if (k == 0) {
k = p - 1;
}
//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";
}