Codeforces 893E - Counting Arrays
思路:质因子分解。
对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数。
相当于把k个小球分配到y个盒子里的方案数。
这个问题可以用隔板法(插空法)解决,要把一段分成y段,需要y-1个隔板,那么有y-1+k个位置,选y-1个位置为隔板,剩下的都是小球,那么方案数为C(y-1+k,y-1)。
如果全为正数,答案就是所有质因子方案数的积。
但是这道题目可以为负数,那么在这y个数里选偶数个变成负数
答案还要乘以C(y,0)+C(y,2)+C(y,4)+C(y,6)+... ③
这个问题是初中组合数的一个经典问题,
设(1+x)^y=C(y,0)*x^0+C(y,1)*x^1+...+C(y,y-1)*x^(y-1)+C(y,y)*x^y
当x=1时,C(y,0)+C(y,1)+...+C(y,y-1)+C(y,y)=2^y ①
当x=-1时,C(y,0)-C(y,1)+C(y,2)-C(y-3)+...=0 ②
①+②=2*③
③式为2^(y-1)
代码:
By ZhihuiLiu, contest: Educational Codeforces Round (Rated for Div. ), problem: (E) Counting Arrays, Accepted, #, hack it! #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int MOD=1e9+;
const int N=1e6+;
ll fac[*N];
ll q_pow(ll n,ll k)
{
ll ans=;
while(k)
{
if(k&)ans=(ans*n)%MOD;
n=(n*n)%MOD;
k>>=;
}
return ans;
}
void init()
{
fac[]=;
for(int i=;i<*N;i++)fac[i]=(fac[i-]*i)%MOD;
}
ll C(ll n,ll m)
{
return (fac[n]*q_pow(fac[m],MOD-))%MOD*q_pow(fac[n-m],MOD-)%MOD;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int q,x,y;
init();
cin>>q;
while(q--)
{
cin>>x>>y;
int c=;
ll ans=q_pow(,y-);
for(int i=;i*i<=x;i++)
{
if(x%i==)
{
int t=;
while(x%i==)
{
t++;
x/=i;
}
ans=(ans*C(t+y-,t))%MOD;
}
}
if(x>)ans=(ans*y)%MOD;
cout<<ans<<endl;
}
return ;
}
Codeforces 893E - Counting Arrays的更多相关文章
- Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论
题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...
- 893E - Counting Arrays
E. Counting Arrays time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个 ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- codeforces 1288C. Two Arrays(dp)
链接:https://codeforces.com/contest/1288/problem/C C. Two Arrays 题意:给定一个数n和一个数m,让构建两个数组a和b满足条件,1.数组中所有 ...
- Codeforces 372B Counting Rectangles is Fun
http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...
- Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)
Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...
- [CodeForces 372A] Counting Kangaroos is Fun
题目链接:http://codeforces.com/problemset/problem/372/A 二分思想 AC代码: #include <cstdio> #include < ...
- codeforces 1140E Palindrome-less Arrays
题目链接:http://codeforces.com/contest/1140/problem/E 题目大意: 如果一个数组的存在一个奇数长的回文就不好. 不是不好的数组是好的. 你可以把-1用1到k ...
随机推荐
- GreenPlum安装greenplum-cc-web监控
一. GreenPlum集群安装环境 由虚拟机搭建的一台master两台segment. 二.安装前准备 1) 所需安装包 GreenPlum监控安装包: greenplum-cc-web-3.0.2 ...
- Qt QDataTime QString 两个类的使用
QDateTime now = QDateTime::currentDateTime(); QString nowStr; nowStr = now.toString("yyyyMMdd_h ...
- css样式属性-字体和隐藏
1.字体 font-family:字体: <body> <div style="font-family:宋体">宋体</div> </bo ...
- TensorFlow中的变量命名以及命名空间.
What: 在Tensorflow中, 为了区别不同的变量(例如TensorBoard显示中), 会需要命名空间对不同的变量进行命名. 其中常用的两个函数为: tf.variable_scope, t ...
- MyBatis学习笔记(八)——Mybatis3.x与Spring4.x整合
转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn arc ...
- iphone6 inline-flex兼容问题
在编写微信端页面时,遇到这样的问题:position属性为flex的导航栏,其li标签在其余设备上显示正常,但在iphone6上浮动错误. 究其原因,是iphone6不支持position属性中的fl ...
- android 简单的控件前端代码
/Hello_word/res/layout/activity_main.xml Graphical Layout/activity_fullsreen.xml(layout/) 代码与设置界面互换 ...
- python的时间处理-time模块
time模块 时间的表示方法有三种: 时间戳:表示的是从1970年1月1日0点至今的秒数 格式化字符串表示:这种表示更习惯我们通常的读法,如2018-04-24 00:00:00 格式化元祖表示:是一 ...
- xargs 原理&使用
1. 简介 之所以能用到这个命令,是由于很多 linux 命令不支持用管道传递参数,例如 find /sbin -perm +700 | ls -l 这个命令是错误的 find /sbin -perm ...
- 20145317彭垚《网络对抗》Exp9 Web安全基础实践
20145317彭垚<网络对抗>Exp9 Web安全基础实践 基础问题回答 SQL注入攻击原理,如何防御? SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询 ...