Divisors_ number of combination factors

Source: Internet
Author: User

Description

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

Input

The input consists of several instances. Each instance consists of a single line containing the 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 16 310 4

Sample Output

2616

"Test instructions" to find the number of the mass factor of C (n,m).

"Theorem" sets all elements of positive integer n decomposition N=p1^a1*p2^a2*p3^a3****ps^as, then t (n) = (a1+1) * (a2+1) * (a3+1) * * * (AN+1); (Formula for number of factors)

1. Find the prime number of n

2.ei=[n/pi^1]+ [n/pi^2]+ ... + [n/pi^n] where [] is rounded. that can be int ei=0;while (N) ei+= (N/=PI);

3. Set formula calculated, m= (e1+1) * (e2+1) *......* (en+1)

#include <iostream>#include<stdio.h>#include<string.h>using namespacestd;Const intn= the;intprime[ +]={2,3,5};intk=3;Long LongN,m,cnt[n][n];voidget_prime ()//Converts the prime number within 1000 to the prime array;intFlag; intp=2;  for(intI=7; i<= +; i+=p) {Flag=0; P=6-p;//has cleverly skipped multiples of 3, improving efficiency for(intj=0;p rime[j]*prime[j]<=i;j++)        {            if(i%prime[j]==0) {flag=1;  Break; }        }        if(!flag) prime[k++]=i; }}voidinit () {memset (CNT,0,sizeof(CNT));    Get_prime (); Long LongTmp,ret;  for(intI=2; i<=431; i++)    {         for(intj=0;p rime[j]<=i;j++) {tmp=i; RET=0;  while(TMP) {tmp=tmp/Prime[j]; RET+=tmp; } Cnt[i][prime[j]]=ret;//i number of quality factors} }}intMain () {init (); Long LongRet,ans;  while(~SCANF ("%lld%lld",&n,&m)) {ans=1;  for(intI=0;p rime[i]<=n;i++) {ret=cnt[n][prime[i]]-cnt[m][prime[i]]-cnt[n-m] [Prime[i]];//c (N,m) =n!/((n-m)!m!), subtracting the number of corresponding factors, we get the result of C (n,m) decomposition ans*= (ret+1); } printf ("%lld\n", ans); }    return 0;}

Divisors_ number of combination factors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.