#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
const int Max = 1e6;
#define MOD 1000003
ll fac[Max];
void init(ll Max)//循环求阶乘
{
fac[0] = 1;
for(int i = 1; i <= Max; i++)
fac[i] = fac[i-1] * i % MOD;
return;
}
ll _pow(ll x, ll y, ll p)//快速幂
{
ll res = 1,tmp = x % p;
while(y)
{
if(y & 1)
res = res * tmp % p;
tmp = tmp * tmp % p;
y >>= 1;
}
return res;
}
ll C(ll n, ll m, ll p)//费马小定理求逆元
{
if(m > n)
return 0;
return fac[n] * _pow(fac[m] * fac[n-m], p-2, p) % p;
}
ll lucas(ll n, ll m, ll p)//lucas递归
{
if(m == 0)
return 1;
return (C(n%p, m%p, p)*lucas(n/p, m/p, p))%p;
}
int main()
{
int t;
cin >> t;
int k = 0;
init(Max);
while(t--)
{
k++;
int n,m;
cin >> n >> m;
cout << "Case " << k << ": " << lucas(n, m, MOD) << endl;
}
return 0;
}
欧拉函数:
#include<iostream>
using namespace std;
int euler(int n)
{
int res=n,i;
for(i=2; i*i<=n; i++)
if(n%i==0)
{
res=res/i*(i-1);
while(n%i==0)
n/=i;
}
if(n>1)
res=res/n*(n-1);
return res;
}
int main()
{
int n;
while(cin>>n&&n)
cout<<euler(n)<<endl;
return 0;
}