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

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`std::counting_semaphore` 是 C++20 新增的同步原语之一,用于控制多个线程间的访问。它是一个计数信号量,可以用来限制同时访问某个资源的线程数量。在类的成员中使用 `std::counting_semaphore` 与在其他地方使用它并没有本质的区别,只需要在类的定义中声明一个 `std::counting_semaphore` 类型的成员即可。 以下是一个简单的示例代码: ```c++ #include <semaphore> #include <thread> #include <iostream> class Example { public: Example() : sema_(2) {} void do_something() { sema_.acquire(); std::cout << "Doing something..." << std::endl; std::this_thread::sleep_for(std::chrono::seconds(1)); sema_.release(); } private: std::counting_semaphore<2> sema_; }; int main() { Example e; std::thread t1(&Example::do_something, &e); std::thread t2(&Example::do_something, &e); std::thread t3(&Example::do_something, &e); t1.join(); t2.join(); t3.join(); return 0; } ``` 在这个例子中,`Example` 类中定义了一个 `std::counting_semaphore<2>` 类型的成员 `sema_`,用于控制同时访问 `do_something` 函数的线程数量。在 `do_something` 函数中,线程首先需要调用 `acquire()` 函数获取信号量,如果当前已经有两个线程在访问,则该线程会被阻塞,直到有一个线程调用了 `release()` 函数释放了信号量。在主函数中,我们创建了三个线程来同时访问 `do_something` 函数,由于信号量的数量是 2,因此最多只有两个线程能够同时访问,第三个线程需要等待前面的线程释放信号量后才能继续执行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值