代码源每日一题div1 拆拆

Daimayuan Online Judge

思路:数论+组合
先不考虑正负号,先对 x x x质因数分解,需要 y y y个数,抽象成 y y y个盒子,每个盒子自带一个 1 1 1,如果没有质因子放入,其就为 1 1 1
例如: x = 12 = 2 ∗ 2 ∗ 3 , y = 3 x=12=2*2*3,y=3 x=12=223,y=3,当我们放入结果为 [ 1 ] [ 1 ∗ 2 ∗ 2 ] [ 1 ∗ 3 ] [1][1*2*2][1*3] [1][122][13],当前贡献结果为 ( 1 , 4 , 3 ) (1,4,3) (1,4,3)
对于相同的质因子,其模型对应为球盒模型中:球(m)相同盒(n)不同允许空盒: C ( n + m − 1 , m − 1 ) C(n+m-1,m-1) C(n+m1,m1)
那么我们处理出相同的质因子后,把结果累乘起来即可
由于数据达到了 1 0 6 10^6 106,因此我们需要预处理出每个数的质因子
我们考虑正负号问题,显然我们只能选取偶数个负号: ∑ 2 ∗ i < y C ( y , 2 ∗ i ) = 2 y − 1 \sum\limits_{2*i<y}C(y,2*i)=2^{y-1} 2i<yC(y,2i)=2y1
最后答案易得: a n s = 2 y − 1 ∗ ∏ i ∈ x . c n t C ( i + y − 1 , y − 1 ) ans=2^{y-1}*\displaystyle \prod\limits_{i\in x.cnt}C(i+y-1,y-1) ans=2y1ix.cntC(i+y1,y1)

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n';
typedef long long ll;
typedef pair<int,int> PII;
const int N=1e6+10,mod=1e9+7;
ll fac[N];
vector<PII>q[N];
void init(){
    fac[0]=1;
    for(int i=1;i<=N;i++)  fac[i]=fac[i-1]*i%mod;
    for(int i=2;i<=N;i++){
        if(q[i].size()) continue;
        for(int j=i;j<N;j+=i){
            int tt=j,cnt=0;
            while(tt%i==0) tt/=i,cnt++;
            q[j].push_back({i,cnt});
        }
    }
}
ll power(ll a,ll b){
    ll ans=1;
    for(;b;b>>=1){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
    }
    return ans;
}
ll inv(ll x){
    return power(x,mod-2);
}
ll C(ll n,ll m){
    return fac[n]*inv(fac[m]*fac[n-m]%mod)%mod;
}
void wraith(){
    int x,y;cin>>x>>y;
    ll ans=power(2,y-1);
    for(int i=0;i<q[x].size();i++){
        ans=ans*C(q[x][i].second+y-1,y-1)%mod;
    }
    cout<<ans<<endl;
}
int main(){
    IOS;
    init();
    int t;cin>>t;
    while(t--){
        wraith();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学不会数据库

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值