很有意思的一个数论题。

是这样的,给你一个数数组a[i],其中给出的每一个数字和要求的数字方位都是[1,m],现在问你根据a[]构造一个b[],且a和b中间的不相等的元素的个数恰好有k个。

现在问你gcd(b[])分别为1,2,……,m的个数分别有多少种可能情况。

额。。。是这样来考虑的。——————容斥原理。

有点像素数筛选,但是复杂一点。

对于个数我们需要从大到小来求解(这里的缘由自己想象就知道了)

假设当前我需要求解有多少个情况满足gcd(b[])=x,那么显然b中的所有的数都必须是x的倍数。

首先我们可以直接统计出来在a中有多少个数不是x的倍数,那么显然这些数是一定要被更改掉的。

如果非x倍数个数大于k个,那么说明当前的个数就是0了。

接下来搞定了不相等的,我们还可能有一种情况就是改变的个数还不够,所以在那些已经是倍数的位置我们还需要进行更改。

这里直接选出组合数,然后依次求出有多少种情况就可以了。

最后把多余的情况减去就得到答案了。

注意不要写挫了,因为很可能由于常数的问题就会T。T_T

#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 300003
#define M 1000000007
typedef long long ll;
using namespace std; int a[maxn],f[maxn],n,m,k,ai,tep;
ll P[maxn],Q[maxn]; ll power(ll x,ll y)
{
if (x==) return ;
if (x== || y==) return ;
ll tot=;
while (y)
{
if (y&) tot=(tot*x)%M;
y>>=;
x=(x*x)%M;
}
return tot;
} ll C(ll x,ll y)
{
if (y== || x==y) return ;
ll tot=(P[x]*Q[y])%M;
tot=(tot*Q[x-y])%M;
return tot;
} int main()
{
ll cur,tot,num;
Q[]=P[]=;
for (int i=; i<maxn; i++) P[i]=(P[i-]*i)%M,Q[i]=power(P[i],M-);
while (scanf("%d%d%d",&n,&m,&k)!=EOF)
{
for (int i=; i<=m; i++) a[i]=f[i]=;
for (int i=; i<=n; i++)
{
scanf("%d",&ai);
a[ai]++;
}
for (int i=m; i>; i--)
{
cur=; tot=; num=m/i;
for (int j=i; j<=m; j+=i) cur+=a[j];
if (n-cur>k)
{
f[i]=;
continue;
}
tot=power(num,n-cur);
if (n-cur!=k)
{
tep=(C(cur,k+cur-n)*power(num-,k+cur-n))%M;
tot=(tot*tep)%M;
}
f[i]=tot;
for (int j=i+i; j<=m; j+=i)
{
f[i]-=f[j];
if (f[i]<) f[i]+=M;
}
}
printf("%d",f[]);
for (int i=; i<=m; i++) printf(" %d",f[i]);
printf("\n");
}
return ;
}

HDU4675_GCD of Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. odoo学习之:在tree view中显示部分数据domain的使用

    只要在window.action中他添加相应东domain即可,如: <!-- 树型列表 --> <record model="ir.actions.act_window& ...

  2. 【转载】GC基本算法及C++GC机制

    原文: GC基本算法及C++GC机制 阅读目录 前言 基本概念 有向可达图与根集 三种基本的垃圾收集算法及其改进算法 1.引用计数算法 2. Mark & Sweep 算法 3. 节点复制算法 ...

  3. (三)SpringBoot2.0基础篇- 持久层,jdbcTemplate和JpaRespository

    一.介绍 SpringBoot框架为使用SQL数据库提供了广泛的支持,从使用JdbcTemplate的直接JDBC访问到完整的“对象关系映射”技术(如Hibernate).Spring-data-jp ...

  4. set get方法诡异的空指针异常

    发现原来是我的bean没有实例化 我的一直都是这么实例化的: UserEntity userEntity = null;难怪每次用不了set方法 原来是没有实例化 实例化之后就能正常使用了 UserE ...

  5. idea 严重: Error configuring application listener of class org.springframework.web.context.Context 后面省略

    根本原因:jar文件没有同步发布到自己项目的lib目录中 解决方案:把之前在这个位置的jar文件,put into 到 /WEB-INF/lib 目录下即可

  6. C#课后小作业

    有关C#基础的练手 跟大家一起分享下 1.让用户输入一个100以内的数 打印1-100之间所有的数,用户输入的数除外 2.让用户输入一个100以内的数 打印1-这个数之间所有的数的和 3.使用一个fo ...

  7. uvaoj 156Ananagrams(map和vector组合使用)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. katalon系列十七:报告&Katalon Analytics

    一.邮件报告Suite执行完后,严格来说这个不算报告,只是邮件通知执行结果,具体设置请看katalon系列三 二.文件报告Suite执行完后,会在项目文件夹下/Report/Suite Name/ti ...

  9. JMeter怎样测试WebSocket

    一.安装WebSocket取样器 1.从JMeter插件管理器官网下载: https://jmeter-plugins.org/ 把这6个jar包放到C:\JMeter\apache-jmeter-3 ...

  10. MySQL☞大结局

    emmm,看了这么多大概会用了点点,学到了一点点 select  列名/*/聚合函数 from  表名1 别名1  连接查询(左外.右外等等) 表名2 别名2 on 关联条件 where 查询条件 g ...