很有意思的一个数论题。

是这样的,给你一个数数组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. 20155321 2016-2017-2《Java程序设计》课程总结

    20155321 2016-2017-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1:我期望的师生关系 预备作业2:学习情况的相关调查 预备作业3:安装虚拟机以及学习Linu ...

  2. # 20155337 《Android程序设计》实验四实验报告

    20155337 <Android程序设计>实验四实验报告 实验一 实验内容 Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPU ...

  3. RHCE-EXAM 模拟题目

    真实考试环境说明: 你考试所用的真实物理机器会使用普通账号自动登陆,登陆后,桌面会有两个虚拟主机图标,分别是system1和system2.所有的考试操作都是在system1和system2上完成.S ...

  4. springboot 中根据数据库表生成所有表的model,mapper和xml文件

    参考文件:https://blog.csdn.net/shenmoren6/article/details/80337662?utm_source=blogxgwz1 详细信息:https://blo ...

  5. .net mvc 使用ueditor的开发(官网没有net版本?)

    1.ueditor的下载导入 官网下载地址:https://ueditor.baidu.com/website/download.html · 介绍 有两种,一种开发版,一种Mini版,分别长这样: ...

  6. selenium自动化之加载浏览器的配置文件

    做seleniumUI自动化关于选用哪个浏览器方面,对于我来说,火狐浏览器只是用于定位元素,因为有firebug(注意高版本的火狐已经安装不了这个插件了),而真正执行自动化脚本用的是谷歌,感觉谷歌的速 ...

  7. python3 selenium实现自动登陆网页

    一.  安装python3与pycharm python安装参考链接:https://www.cnblogs.com/hepeilinnow/p/9727922.html pycharm最好安装专业版 ...

  8. Java EE平台介绍(译)

    Java EE平台介绍 2.1 企业应用总览 这一部分将对企业应用及其设计和开发进行简单介绍. 就像之前说的,Java EE 平台是为了帮助开发者开发大规模.多层次.可伸缩.服务可靠.网络安全的应用而 ...

  9. 百度地图之自动提示--autoComplete

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. TCP半开连接与半闭连接

    半打开(Half-Open)连接和半关闭(Half-Close)连接.TCP是一个全双工(Full-Duplex)协议,因此这里的半连接"半"字就是相对于全双工的"全&q ...