poj 2992 Divisors

Divisors
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7846   Accepted: 2163

Description

Your task in this problem is to determine the number of divisors of Cnk. Just for fun -- or do you need any special reason for such a useful computation?

Input

The input consists of several instances. Each instance consists of a single line containing two integers n and k (0 ≤ k ≤ n ≤ 431), separated by a single space.

Output

For each instance, output a line containing exactly one integer -- the number of distinct divisors of Cnk. For the input instances, this number does not exceed 263 - 1.

Sample Input

5 1
6 3
10 4

Sample Output

2
6
16
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
const int MAXN = 431;
int pCnt, prime[MAXN / 4];

void getPrime(int n) {
int i, j, notPrime[MAXN + 1];
memset(notPrime, 0, sizeof(notPrime));
pCnt = 0;
for(i = 2; i <= n; i ++) {
if(! notPrime[i]) prime[pCnt ++] = i;
for(j = 0; j < pCnt && prime[j] * i <= n; j ++) {
notPrime[prime[j] * i] = prime[j];
if(i % prime[j] == 0)
break;
}
}
}
int cal(int n, int p) {
if(n < p) return 0;
else return n / p + cal(n / p, p);
}
int main() {
getPrime(MAXN);
int i, n, k;
while(scanf("%d%d", &n, &k) != EOF) {
__int64 cnt = 1;
//if(k > n / 2) k = n - k;
for(i = 0; prime[i] <= n && i < pCnt; i ++) {
int t = cal(n, prime[i]) - cal(n - k, prime[i]) - cal(k, prime[i]);
cnt *= (t + 1);
}
printf("%I64d\n", cnt);
}
return(0);
}

posted @ 2011-11-22 13:56  w0w0  阅读(180)  评论(0)    收藏  举报