
Divisors
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 9940 | Accepted: 2924 |
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<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<iostream>
#include<algorithm>
using namespace std;
int p[]={},t,pp[];
void init()
{
int i,j;
t=;
for(i=; i<; i++)
{
if(!p[i])
{
p[t++]=i;
j=i*i;
while(j<)
{
p[j]=;
j+=i;
}
}
}
}
void fun(int n,int q)
{
int i,j,m,sum;
for(i=; p[i]<=n&&i<t; i++)
{
m=n;
sum=;
while(m)
{
m/=p[i];
sum+=m;
}
if(q)
pp[i]+=sum;
else pp[i]-=sum;
}
}
int main()
{
init();
int n,k,i;
while(~scanf("%d%d",&n,&k))
{
memset(pp,,sizeof(pp));
fun(n,);
fun(k,);
fun(n-k,);
long long sum=;
for(i=; i<t; i++)
{
if(pp[i])sum*=pp[i]+;
}
printf("%lld\n",sum);
}
}