CF893E:Counting Arrays(数学 & 组合数)

本文介绍了一种计算特定条件下x的y因子分解方案数量的方法,通过质因数分解和组合数学来解决计数问题,并提供了完整的C++实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

E. Counting Arrays
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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.

Output

Print q integers. i-th integer has to be equal to the number of yi-factorizations of xi modulo 109 + 7.

Example
input
2
6 3
4 2
output
36
6
Note

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的组成质因数,所以对x的每种质因子独立考虑,x拆成p1^a1*p2^a2...每个素数相当于将ai个球放到y个桶允许有空桶的模型,乘起来就是了。至于符号肯定是偶数个,再乘个pow(2, y-1)就ok。

# include <iostream>
# include <cstdio>
# include <cstring>
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
const int maxn = 1e6+30;
LL inv[maxn+3] = {1,1}, fac[maxn+3] = {1,1}, fi[maxn+3] = {1,1};
int f2[maxn+3]={1,2},lowp[maxn+3];
void init()
{
    memset(lowp, -1, sizeof(lowp));
    for(int i=2; i<=maxn; ++i)
    {
        if(lowp[i] == -1)
            for(int j=i; j<=maxn; j+=i) if(lowp[j] == -1) lowp[j]=i;
        f2[i] = f2[i-1]*2%mod;
        fac[i] = fac[i-1]*i%mod;
        inv[i] = (mod-mod/i)*inv[mod%i]%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}
inline LL C(LL n, LL m)//计算组合数
{
    if(n<m) return 0;
    return fac[n]*fi[m]%mod*fi[n-m]%mod;
}
int main()
{
    init();
    int t, x, y;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&x,&y);
        LL ans = f2[y-1];
        while(x != 1)
        {
            int p = lowp[x], cnt=0;
            while(lowp[x] == p)
            {
                x /= p;
                ++cnt;
            }
            ans = ans*C(y+cnt-1,cnt)%mod;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值