HDU4675_GCD of Sequence
很有意思的一个数论题。
是这样的,给你一个数数组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的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- Java——基于java自身包实现消息系统间的通信(TCP/IP+NIO)
/** * Created by LiuHuiChao on 2016/11/15. * description:based on TCP/IP+NIO to deliver the message ...
- 【LG2183】[国家集训队]礼物
[LG2183][国家集训队]礼物 题面 洛谷 题解 插曲:不知道为什么,一看到这个题目,我就想到了这个人... 如果不是有\(exLucas\),这题就是\(sb\)题... 首先,若\(\sum_ ...
- Drupal7 针对特定条件才显示区块
当D7中开启PHP filter模块. Text format就会多出“PHP Code”选项. 而且,新建block时也会多出"Pages on which PHP code return ...
- IBM X3650M4简单排错方法
如果出问题了,首先看开机的那个地方的灯是否显示正常,有黄色的灯亮一般都不正常: 这种服务器带有一个错误指示板,只需要在电源开关那,如上图,把那个蓝色的按钮往里面按,就能把里面的一个板子抽出来,可以看到 ...
- Centos7使用yum安装MySQL5.6的正确姿势
centos自带的repo是不会自动更新每个软件的最新版本,所以无法通过yum方式安装MySQL的高级版本. 所以,即使使劲用yum -y install mysql mysql-server mys ...
- Linux 防火墙设置(转)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- 622.设计循环队列 javascript实现
设计你的循环队列实现. 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环.它也被称为“环形缓冲器”. 循环队列的一个好处是我们可以利用这个队列 ...
- Python爬虫入门(7):正则表达式
下面就开始介绍一个十分强大的工具,正则表达式! 1.了解正则表达式 正则表达式是对字符串操作的一种公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串” ...
- 爬虫:Scrapy12 - Stats Collection
Scrapy 提供了方便的收集数据的机制.数据以 key/value 方式存储,值大多是计数值.该机制叫做数据收集器(Stats Collector),可以通过 Crawler API 的属性 sta ...
- Alpha发布用户使用报告【欢迎来怼】
目录 用户统计表 部分用户评论截图 用户统计图 总结 一.用户统计表 目前,博客园安卓版的用户已达到11位.为了采集到更加客观公正的用户评价,并没有将团队内部人员的评价统计进来.同时,为了更好地保护用 ...