Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接
题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数。
思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个质因子的贡献就相当于把kkk个PiP_iPi放到yyy个盒子中,且盒子可能为空,方案为C(k+y−1,y)C(k+y-1,y)C(k+y−1,y),然后每个质因子的方案乘在一起即可。最后,因为负号也会出现,但xxx为正,所以就是在yyy个位置上选偶数个位置放负号,方案为2y−12^{y-1}2y−1再乘起来即可。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e6 +11;
const LL mod=1e9+7;
LL Fac[N+33],Inv[N+33];
int p[N+33],a[N+33],cnt;
void init(){
Fac[0]=1;
for(int i=1;i<=N;i++)Fac[i]=(Fac[i-1]*i)%mod;
Inv[N]=powmod(Fac[N],mod-2,mod);
for(int i=N-1;i>=1;i--)Inv[i]=(Inv[i+1]*(i+1))%mod;
Inv[0]=1;
}
void P(){
for(int i=2;i<N;i++){
if(!p[i])a[++cnt]=i;
for(int j=1;j<=cnt&&1ll*a[j]*i<N;j++){
p[a[j]*i]=1;
if(i%a[j]==0)break;
}
}
}
LL C(int x,int y){
return 1ll*Fac[x]*Inv[y]%mod*Inv[x-y]%mod;
}
int main(){
ios::sync_with_stdio(false);
init();
int t;
P();
for(cin>>t;t;t--){
int x,y;
cin>>x>>y;
LL ans=1;
for(int i=1;i<=cnt&&1ll*a[i]*a[i]<=x;i++){
if(x%a[i]==0){
int res=0;
while(x%a[i]==0)res++,x/=a[i];
ans=ans*C(res+y-1,y-1);
ans%=mod;
}
}
if(x>1)ans=ans*C(y,y-1)%mod;
cout<<ans*powmod(2,y-1,mod)%mod<<endl;
}
return 0;
}
Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays的更多相关文章
- Educational Codeforces Round 33 (Rated for Div. 2) F. Subtree Minimum Query(主席树合并)
题意 给定一棵 \(n\) 个点的带点权树,以 \(1\) 为根, \(m\) 次询问,每次询问给出两个值 \(p, k\) ,求以下值: \(p\) 的子树中距离 \(p \le k\) 的所有点权 ...
- Educational Codeforces Round 33 (Rated for Div. 2) 题解
A.每个状态只有一种后续转移,判断每次转移是否都合法即可. #include <iostream> #include <cstdio> using namespace std; ...
- Educational Codeforces Round 33 (Rated for Div. 2)A-F
总的来说这套题还是很不错的,让我对主席树有了更深的了解 A:水题,模拟即可 #include<bits/stdc++.h> #define fi first #define se seco ...
- Educational Codeforces Round 33 (Rated for Div. 2) D. Credit Card
D. Credit Card time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Educational Codeforces Round 33 (Rated for Div. 2) C. Rumor【并查集+贪心/维护集合最小值】
C. Rumor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Educational Codeforces Round 33 (Rated for Div. 2) B. Beautiful Divisors【进制思维/打表】
B. Beautiful Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 33 (Rated for Div. 2) A. Chess For Three【模拟/逻辑推理】
A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 33 (Rated for Div. 2)
A. Chess For Three time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 33 (Rated for Div. 2) D题 【贪心:前缀和+后缀最值好题】
D. Credit Card Recenlty Luba got a credit card and started to use it. Let's consider n consecutive d ...
随机推荐
- CentOS 7 中使用NTP进行时间同步
1. NTP时钟同步方式说明NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步: 直接同步 使用ntpdate命令进行同步,直接进行时间变更.如果服务器上存在一个12点运行的任务,当前服 ...
- 实现element-ui中table点击一行展开
转:https://www.jianshu.com/p/e51ba4cb11d6 先上效果 效果图 三要素 1.row-click 点击行 2.ref 自行了解vue 3.toggleRowExp ...
- jenkins之Job建立-运行 git 脚本
新建一个自由风格的项目,运行git脚本 1.点击菜单栏中的“新任务” 2.进入该页面后输入一个项目名称,然后选择“构建一个自由风格的软件项目”,滑动到最底端,点击ok(在左下角) 3.进入下图页面后 ...
- Web前端知识点记录
一.HTML的加载顺序 浏览器边下载HTML,边解析HTML代码,二者是从上往下同步进行的 先解析<head>中的代码,在<head>中遇到了<script>标签, ...
- eclipse上配置svn
eclipse里安装SVN插件,一般来说,有两种方式: 直接下载SVN插件,将其解压到eclipse的对应目录里 使用eclipse 里Help菜单的“Install New Software”,通过 ...
- java oop 集合框架
集合主要是用来存放数据的,集合与数组的主要区别在于,集合的大小不受限制,而数组的大小受限制,在使用集合增加数据时又常常与泛型联系起来,所以集合和泛型在实际开发过程中总会结合在一起 数组致命的缺点是数组 ...
- [转帖]Go中的下划线
Go中的下划线 https://blog.csdn.net/wanglei9876/article/details/50475864 下划线的作用: 在import 时 是仅引入 init 函数 在正 ...
- linux 运维工程师发展路线
linux运维发展常见的就是下面两条路线:第一条:运维应用-->系统架构-->运维开发-->系统开发第二条:运维应用-->应用dba-->架构dba-->开发DBA ...
- mysql的时区错误问题: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one
问题:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.. ...
- LODOP设置打印设计返回JS代码是变量
前面有一篇博文是介绍JS模版的加载和赋值,赋值有两种,详细可查看本博客的那篇博文:LodopJS代码模版的加载和赋值简单来说,就是打印项的值是变量,在添加打印项前进行赋值:打印项的值是字符串,给打印项 ...