• hdu4390-Number Sequence(容斥计算)


    题意:给定b数列。计算有多少种数列 a1,a2,...,an 满足条件 a1*a2*...*an=b1*b2*…*bn (ai>1).


    解法:处理出b数列中出现的全部质因子的数量记录在map中,然后进行容斥计算:

    代码:

    /******************************************************
    * author:xiefubao
    *******************************************************/
    #pragma comment(linker, "/STACK:102400000,102400000")
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <queue>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <stack>
    #include <string.h>
    //freopen ("in.txt" , "r" , stdin);
    using namespace std;
    
    #define eps 1e-8
    #define zero(_) (abs(_)<=eps)
    const double pi=acos(-1.0);
    typedef long long LL;
    const int Max=1000010;
    const int INF=1000000007;
    
    map<int,int> maps;
    int num[30];
    int n;
    bool rem[1000010];
    LL C[500][500];
    int prime[Max/2];
    int p=0;
    void init()
    {
        for(LL i=2; i<Max; i++)
            if(!rem[i])
            {
                prime[p++]=i;
                for(LL j=i*i; j<Max; j+=i)
                    rem[j]=1;
            }
        for(int i=0; i<500; i++)
            for(int j=0; j<=i; j++)
                C[i][j]=j?

    (C[i-1][j-1]+C[i-1][j])%INF:1; } void make(int t) { int tool=t; for(int i=0; prime[i]*prime[i]<=t; i++) { while(tool%prime[i]==0) maps[prime[i]]++,tool/=prime[i]; } if(tool>=2) maps[tool]++; } LL getans(int m) { LL ans=1; int k=n-m; for(map<int,int>::iterator p=maps.begin();p!=maps.end();p++) { int t=p->second; ans=(ans*C[k+t-1][k-1])%INF; } return ans; } int main() { init(); while(scanf("%d",&n)==1) { maps.clear(); for(int i=0; i<n; i++) scanf("%d",num+i); for(int i=0; i<n; i++) { make(num[i]); } int ans=0; for(int i=0; i<n; i++) { if(i&1) { ans-=C[n][i]*getans(i)%INF; if(ans<0) ans+=INF; } else { ans+=C[n][i]*getans(i)%INF; if(ans>=INF) ans-=INF; } } cout<<ans<<' '; } return 0; }






                                                                     

  • 相关阅读:
    怎么统计指定文件夹下含有.xml格式的文件数目
    SQLServer触发器创建、删除、修改、查看
    Devexpress 学习不错的网址
    Devexpress
    SQL 查找重复项及批量修改数据成固定格式
    elementui carousel不能自适应问题
    node中console自定义样式
    forEach for for in for of性能问题
    骚东西
    关于arr.map()问题
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/7069136.html
Copyright © 2020-2023  润新知