893E - Counting Arrays
3 seconds
256 megabytes
standard input
standard output
You are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met:
- There are y elements in F, and all of them are integer numbers;
.
You have to count the number of pairwise distinct arrays that are y-factorizations of x. Two arrays A and B are considered different iff there exists at least one index i (1 ≤ i ≤ y) such that Ai ≠ Bi. Since the answer can be very large, print it modulo 109 + 7.
The first line contains one integer q (1 ≤ q ≤ 105) — the number of testcases to solve.
Then q lines follow, each containing two integers xi and yi (1 ≤ xi, yi ≤ 106). Each of these lines represents a testcase.
Print q integers. i-th integer has to be equal to the number of yi-factorizations of xi modulo 109 + 7.
2
6 3
4 2
36
6
In the second testcase of the example there are six y-factorizations:
- { - 4, - 1};
- { - 2, - 2};
- { - 1, - 4};
- {1, 4};
- {2, 2};
- {4, 1}.
题意:给出x,y。求满足含有y个元素的之积是x的数列个数。
思路:排列组合,插空法。
代码:
#include<bits/stdc++.h>
#define db double
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define debug puts("-------------");
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod-;
const db eps = 1e-;
const db PI = acos(-1.0);
using namespace std;
bool v[N];
int pri[N];
ll F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘 int p=;
void init()
{
memset(v,,sizeof(v));
for(int i=;i<;i++){
if(!v[i]) pri[p++]=i;
for(int j=*i;j<;j+=i) {v[j]=;}
}
inv[] = ;
for(int i = ; i < ; i ++){
inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;
}
F[] = Finv[] = ;
for(int i = ; i < ; i ++){
F[i] = F[i-] * 1ll * i % mod;
Finv[i] = Finv[i-] * 1ll* inv[i] % mod;
}
}
ll C(ll n, ll m){ //comb(n, m)就是C(n, m)
if(m < || m > n) return ;
return F[n] * 1ll * Finv[n - m] % mod * Finv[m] % mod;
}
ll qpow(ll x,ll n)
{
ll ans=;
x%=mod;
while(n){
if(n&) ans=ans*x%mod;
x=x*x%mod;
n>>=;
}
return ans;
} int main(){
int q;
ci(q);
init();
for(int i=;i<q;i++)
{
ll x,y;
cl(x),cl(y);
ll ans=qpow(,y-);
if(x==){
pl(qpow(, y - ));
continue;
}
vector<int> e;e.clear();
map<int,int> mp;mp.clear();
int id=;
while(x>){
if(x%pri[id]==){
int n=;
while(x%pri[id]==) n++,x/=pri[id];
ans=ans*C(n+y-,y-)%mod;
}
id++;
if(pri[id]>){
if(x>) ans=ans*y%mod;
break;
}
}
pl(ans);
}
return ;
}
893E - Counting Arrays的更多相关文章
- Codeforces 893E - Counting Arrays
893E - Counting Arrays 思路:质因子分解. 对于每个质因子,假设它有k个,那么求把它分配到y个数上的方案数. 相当于把k个小球分配到y个盒子里的方案数. 这个问题可以用隔板法(插 ...
- Codeforces 893E Counting Arrays:dp + 线性筛 + 分解质因数 + 组合数结论
题目链接:http://codeforces.com/problemset/problem/893/E 题意: 共q组数据(q <= 10^5),每组数据给定x,y(x,y <= 10^6 ...
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays
题目链接 题意:给你两个数x,yx,yx,y,让你构造一些长为yyy的数列,让这个数列的累乘为xxx,输出方案数. 思路:考虑对xxx进行质因数分解,设某个质因子PiP_iPi的的幂为kkk,则这个 ...
- Educational Codeforces Round 33
# Who = Penalty * A B C D E F 479 arkethos 4 247 + 00:08 + 00:19 +1 00:59 +2 01:41 479 ne-leo ...
- counting elements--codility
lesson 4: counting elements 1. FrogRiverOne 2. PermCheck 3. MissingInteger 4. MaxCounters lesson 4: ...
- 排序算法六:计数排序(Counting sort)
前面介绍的几种排序算法,都是基于不同位置的元素比较,算法平均时间复杂度理论最好值是θ(nlgn). 今天介绍一种新的排序算法,计数排序(Counting sort),计数排序是一个非基于比较的线性时间 ...
- 【算法】计数排序(Counting Sort)(八)
计数排序(Counting Sort) 计数排序不是基于比较的排序算法,其核心在于将输入的数据值转化为键存储在额外开辟的数组空间中. 作为一种线性时间复杂度的排序,计数排序要求输入的数据必须是有确定范 ...
- Java程序员的日常—— Arrays工具类的使用
这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...
- 使用 Arrays 类操作 Java 中的数组
Arrays 类是 Java 中提供的一个工具类,在 java.util 包中.该类中包含了一些方法用来直接操作数组,比如可直接实现数组的排序.搜索等(关于类和方法的相关内容在后面的章节中会详细讲解滴 ...
随机推荐
- mysql数据库忘记密码时如何修改(二)
第一步:找到mysql数据库的my.ini配置文件,在[mysqld]下面添加一行代码:skip-grant-tables 第二步:运行services.msc进入服务管理界面,重启mysql服务. ...
- Servlet和JavaBean
1.Servlet简介: Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间 ...
- 【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:10.项目介绍之架构(2)
欢迎阅读我的开源项目<迷你微信>服务器与<迷你微信>客户端 前言 前面我们讲到<迷你微信>服务器端的主架构,现在我们来描述一下它的模块详细信息. 网络模块 从上图我 ...
- 【java】使用URL和CookieManager爬取页面的验证码和cookie并保存
使用java的net包和io包下的几个工具爬取页面的验证码图片并保存到本地. 然后可以把获取的cookie保存下来,做进一步处理.比如通过识别验证码,进一步使用验证码和用户名,密码,保存下来的cook ...
- WORD窗体保护密码清除
Word 2003破解方法如下:1.用Word打开已设置有密码的“保护文档”(原始DOC文件):2.菜单中选择“文件”→“另存为Web页”,保存为HTML文件然后关闭Word:3.用文本编辑器(如:记 ...
- jq实现剪裁图片设置为头像
有时候我们需要设置为这样,就是将某些图片设置为剪裁成设置的尺寸:就是这样的 插件的地址: http://www.htmleaf.com/jQuery/Image-Effects/20150421171 ...
- linux 命令——33 df(转)
linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...
- 【ML】聊天机器人
继做过了泰语分词,自动对对对联后对聊天机器人产生了浓厚的兴趣.ChatBot集合了NLP,DL等多领域的应用. https://deeppavlov.ai/ https://www.rasa.com/ ...
- python_24_test
product_list=[ ('Iphone',5800), ('Mac Pro',9800), ('Bike',800), ('Watch',10600), ('Coffee',31), ('Py ...
- 两级宏&&字符串化宏
如果你想字符串化宏参数扩展的结果,你必须使用两个级别的宏. #define xstr(s) str(s) #define str(s) #s #define foo 4 str (foo) ==> ...