• Nk 1430 Divisors(因子数与质因数)


    Time Limit: 5000 ms    Memory Limit: 10000 kB  
    Total Submit : 432 (78 users)   Accepted Submit : 108 (57 users)   Page View : 3479  Font Style: Aa Aa Aa
    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 4Sample Output
    2
    6
    16

    代码如下:12=2^2*3^1 因子个数就等于(2+1)*(1+2)=12

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int num;
    bool a[450];
    
    struct prime
    {
        int num;
        int count;
    }p[200];
    
    void init()
    {
        int i,j;
        memset(a,true,sizeof(a));
        num=0;
        for(i=2;i<450;i++)
        {
            if(a[i]) p[num++].num=i;
            for(j=0;j<num&&i*p[j].num<450;j++)
            {
                a[p[j].num*i]=0;
                if(i%p[j].num==0)
                    break;
            }
        }
    }
    
    __int64 Deal(int n,int m)
    {
        int i,j;
        int a,b;
        __int64 sum=1;
        if(m*2<n)
            a=n,b=n-m;
        else 
            a=n,b=m;
        for(i=0;i<num;i++)
            p[i].count=0;
        for(i=b+1;i<=a;i++)
        {
            int t=i;
            for(j=0;p[j].num<=i && j<num && t!=1;j++)
            {
                while(t%p[j].num==0)
                {
                    t/=p[j].num;
                    p[j].count++;
                }
            }
        }
        for(i=2;i<=a-b;i++)
        {
            int t=i;
            for(j=0;p[j].num<=i && j<num && t!=1;j++)
            {
                while(t%p[j].num==0)
                {
                    t/=p[j].num;
                    p[j].count--;
                }
            }
        }
        for(i=0;i<num;i++)
        {
            if(p[i].count)
                sum*=(p[i].count+1);
        }
        return sum;
    }
    
    int main()
    {
        int n,m;
        init();
        while(cin>>n>>m)
            printf("%I64d
    ",Deal(n,m));
        return 0;
    }
  • 相关阅读:
    go test 下篇
    go test 上篇
    利用Docker Compose快速搭建本地测试环境
    phinx:php数据库迁移
    tp5 r3 一个简单的SQL语句调试实例
    TP开发小技巧
    优酷真实视频地址解析——2014年10月7日
    霍夫变换
    Google Earth影像数据破解之旅
    线程理论:(四)锁优化
  • 原文地址:https://www.cnblogs.com/xiong-/p/3202473.html
Copyright © 2020-2023  润新知