URAL_1055

    将组合数展开后的每个数依次分解素因子,最后再统计一下有多少种素因子就可以了。

#include<stdio.h>
#include<string.h>
#define MAXD 1010
#define MAXN 50010
int N, M, isprime[MAXD], prime[MAXD], P, h[MAXN];
void prepare()
{
    int i, j;
    P = 0;
    memset(isprime, -1, sizeof(isprime));
    for(i = 2; i <= 1000; i ++)
        if(isprime[i])
        {
            prime[P ++] = i;
            for(j = i * i; j <= 1000; j += i)
                isprime[j] = 0;
        }
}
void deal(int n, int d)
{
    int i;;
    for(i = 0; prime[i] * prime[i] <= n; i ++)
        while(n % prime[i] == 0)
            h[prime[i]] += d, n /= prime[i];
    h[n] += d;
}
void solve()
{
    int i, ans = 0;
    memset(h, 0, sizeof(h));
    for(i = N - M + 1; i <= N; i ++)
        deal(i, 1);
    for(i = 1; i <= M; i ++)
        deal(i, -1);
    for(i = 2; i <= N; i ++)
        if(h[i])
            ++ ans;
    printf("%d\n", ans);
}
int main()
{
    prepare();
    while(scanf("%d%d", &N, &M) == 2)
    {
        solve();
    }
    return 0;
}