Comet OJ - Contest #2 C 言论的阴影里妄想初萌//概率+ksm+逆元

https://cometoj.com/contest/37/problems 

题意:上面很明显了

直接枚举有1-n条边的子集的期望。

 中间卡了我好久一个问题,quick_mod(a,b,mod),b爆int变成负数,-1>>1=-1,一直TLE。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int max_n = 1e5+6;
void exgcd(LL a, LL b, LL &x, LL &y, LL &d) {
    if (!b)
        {d = a, x = 1, y = 0;}
    else{
        exgcd(b, a % b, y, x, d);
        y -= x * (a / b);
    }
}
LL inv(LL t, LL p){
    LL d, x, y;
    exgcd(t, p, x, y, d);
    return (x % p + p) % p;
}
LL quick_mod(LL aqa,LL  nqn,LL mood){
    LL ret=1;
    while(nqn){
        if(nqn&1){
            ret=(ret*aqa)%mood;
        }
        aqa=(aqa*aqa)%mood;
        nqn=nqn>>1;
    }
    return ret;
}

int main(){
    int n,x,y;scanf("%d%d%d",&n,&x,&y);
    LL xy=x*inv(y,mod)%mod;LL ans=1+n,c=n;
    for(int i=2;i<=n;i++){
        c=c*inv(i,mod)%mod*(n-i+1)%mod;
        ans=(ans+c*quick_mod(xy,i*(i-1)/2,mod)%mod)%mod;
    }
    printf("%lld",ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值