题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675

题意:给出n,m,K,一个长度为n的数列A(1<=A[i]<=m)。对于d(1<=d<=m),有多少个长度为n的数列B满足:

(1)1<=B[i]<=m;

(2)Gcd(B[1],B[2],……,B[n])=d;

(3)恰有K个位置满足A[i]!=B[i]。

思路:

i64 p[N];

void init()
{
    p[0]=1;
    int i;
    FOR1(i,N-1) p[i]=p[i-1]*i%mod;
}

i64 exGcd(i64 a,i64 b,i64 &x,i64 &y)
{
    if(b==0)
    {
        x=1; y=0;
        return a;
    }
    i64 temp=exGcd(b,a%b,x,y);
    i64 t=x;
    x=y;
    y=t-a/b*y;
    return temp;
}

i64 reverse(i64 a,i64 b)
{
    i64 x,y;
    exGcd(a,b,x,y);
    x%=b;
    if(x<0) x+=b;
    return x;
}

i64 C(int n,int m)
{
    return p[n]*reverse(p[m]*p[n-m]%mod,mod)%mod;
}

i64 Pow(i64 a,i64 b)
{
    i64 ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}

i64 a[N],g[N];
int b[N];
int n,m,K;

int main()
{
    init();
    Rush(n)
    {
        RD(m,K);
        int i,j,x;
        FOR1(i,m) b[i]=a[i]=0;
        FOR1(i,n) RD(x),a[x]++; 
        for(i=m;i>=1;i--) 
        {
            for(j=i;j<=m;j+=i) b[i]+=a[j];
        }
        FOR1(i,m) 
        {
            if(b[i]>=n-K) g[i]=Pow(m/i,n-b[i])*Pow(m/i-1,b[i]-(n-K))%mod*C(b[i],n-K)%mod;
            else g[i]=0;
        }
        for(i=m;i>=1;i--) 
        {
            for(j=i+i;j<=m;j+=i) 
            {
                g[i]-=g[j];
                if(g[i]<0) g[i]+=mod;
            }
        }
        FOR1(i,m-1) printf("%I64d ",g[i]);
        PR(g[i]);
    }
}

HDU 4675 GCD of Sequence(容斥)的更多相关文章

  1. HDU 4675 GCD of Sequence (2013多校7 1010题 数学题)

    GCD of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  2. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  3. HDU - 4675 GCD of Sequence (莫比乌斯反演+组合数学)

    题意:给出序列[a1..aN],整数M和k,求对1-M中的每个整数d,构建新的序列[b1...bN],使其满足: 1. \(1 \le bi \le M\) 2. \(gcd(b 1, b 2, -, ...

  4. HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解

    题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...

  5. hdu 4675 GCD of Sequence

    数学题! 从M到1计算,在计算i的时候,算出原序列是i的倍数的个数cnt: 也就是将cnt个数中的cnt-(n-k)个数变掉,n-cnt个数变为i的倍数. 且i的倍数为t=m/i; 则符合的数为:c[ ...

  6. HDU 5297 Y sequence 容斥 迭代

    Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...

  7. GCD HDU - 1695 (欧拉 + 容斥)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. HDU 6053 TrickGCD 莫比乌斯函数/容斥/筛法

    题意:给出n个数$a[i]$,每个数可以变成不大于它的数,现问所有数的gcd大于1的方案数.其中$(n,a[i]<=1e5)$ 思路:鉴于a[i]不大,可以想到枚举gcd的值.考虑一个$gcd( ...

  9. HDU 5768 Lucky7 (中国剩余定理+容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5768 给你n个同余方程组,然后给你l,r,问你l,r中有多少数%7=0且%ai != bi. 比较明显 ...

随机推荐

  1. Ubuntu系统下USB转串口的使用

    PC系统是Ubuntu12.04,与路由器开发板之间用USB转串口线连接. 一.硬件连接 确认Ubuntu对USB转串口设备的支持. 1.# lsmod | grep usbserial如果有usbs ...

  2. 使用node的http模块实现爬虫功能,并把爬到的数据存入mongondb

    刚开始使用http中间件做爬虫其实蛮多坑的,最主要的坑就是编码问题,有很多中文网站的采用的gb2313的编码方式,这个在爬到的报文解析就很蛋碎, 因为http中间件对utf-8支持的比较好,所以针对这 ...

  3. 找不到对应的webservice配置参数[ProcessService]

    在UI端 保存时 界面显示无法保存 且报此错误 “找不到对应的webservice配置参数[ProcessService]” 此下为解决方法: 首先 在[应用管理平台]--[参数模板设置] 找到你的参 ...

  4. leetcode Triangle及其思考

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  5. Chp14: Java

    1.finally keyword: finally keyword is used in association with a try/catch block and guarantees that ...

  6. Chp18: Hard

    18.1 Write a function that adds two numbers. You should not use + or any arithmetic operators. Solut ...

  7. auto_ptr的设计动机

    auto_ptr的设计动机 C++标准程序库提供的auto_ptr是一种智能型指针(smart pointer),帮助程序员防止“被异常抛出时发生资源泄露”. 函数的操作经常依以下模式进行: 1.获取 ...

  8. HDOJ 1284 钱币兑换问题

    转自:wutianqi http://www.wutianqi.com/?p=981 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 tag:母 ...

  9. mac上eclipse上运行word count

    1.打开eclipse之后,建立wordcount项目 package wordcount; import java.io.IOException; import java.util.StringTo ...

  10. 【转载】SSH框架总结(将网上朋友写的给整合了下)

    一.Struts 在没有学习SSH框架前,我们一般采用Jsp+javabean+servlet开发,这里就是MVC架构.而Struts其实就是替代了Servlet,我们知道Servlet在一般的开发中 ...