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 ...
随机推荐
- DIV+CSS实现竖排按钮样式
<div class="btn_left btn_left1">每日单元成功率</div><br/> <div class="b ...
- 面向忙碌开发者的 Android
面向忙碌开发者的 Android passiontim 关注 2016.11.19 21:41* 字数 4013 阅读 2967评论 2喜欢 92 面向忙碌开发者的 Android 视频教程(Tuts ...
- Mysql取消SSH链接和恢复SSH链接
取消SSH链接//键入密码,链接上mysql mysql -u root -p USE MYSQL; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIF ...
- Appium+python 自动发送邮件(1)(转)
(原文:https://www.cnblogs.com/fancy0158/p/10056091.html) SMTP:简单传输协议,实在Internet上传输Email的事实标准. Python的s ...
- katalon系列十五:给浏览器添加cookie自动登陆
import org.openqa.selenium.Cookieimport org.openqa.selenium.WebDriverimport com.kms.katalon.core.web ...
- 发送请求工具—Advanced REST Client的安装使用
1. 0 下载得到Advanced-REST-client_v3.1.9.zip 链接:http://pan.baidu.com/s/1c0vUnJi 密码:z34d 1.1 解压Advanced-R ...
- 03-运行第一个docker容器
环境选择 容器需要管理工具.runtime 和操作系统,我们的选择如下: 1.管理工具 - Docker Engine因为 Docker 最流行使用最广泛. 2.runtime - runc Dock ...
- JavaScript学习笔记(一)——JS速览
第一章 JS速览 1 限制时间处理事件 <script> setTomeout(wakeUpUser,5000); function wakeUpUser() { alert(" ...
- python购物车优化
一.需求分析 拥有用户接口和商家接口 用户能够进行消费记录查询,充值,购物等功能,消费记录存储于数据库 商家可以进行商品的增删改等操作 二.程序流程图 程序大致流程图如下: 三.代码实现 本程序分成两 ...
- 如何在HPUX的终端提示符前显示当前登录用户信息和所在目录
修改/etc/default/profile文件,在最后加上如下内容: case $LOGNAME in 'root') PS1="$LOGNAME@$(hostname): ...