zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    vs中无法找到头文件
    c++ vector 用法
    c++ queue 用法
    c++ 中 毫秒级时间获取
    vs2013 boost signals
    vs2013环境下boost配置
    C++ static 用法
    fopen()和fclose()
    删除字符串尾的回车符
    WaitForSingleObject()
  • 原文地址:https://www.cnblogs.com/xiong-/p/3202473.html
Copyright © 2011-2022 走看看