J Roulette(“范式杯”2023牛客暑期多校训练营1)

目录

题目描述:

解题思路:

 解题代码:


题目描述:

解题思路:

 

注:其中对于取模过程中用到了费马小定理,可参考如下博客:

(3条消息) 费马小定理及其应用_CTGU-Yoghurt的博客-CSDN博客

推算如下:

 解题代码:

#include<iostream> 
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;

const int N=1e5+6;
const int M=998244353;

ll n,m;

ll qsm(ll x,ll p){
    ll res=1;
    while(p){
        if(p&1) res=res*x%M;
        x=x*x%M;
        p>>=1;
    }
    return res%M;
}

ll inv(ll x){
    return qsm(x,M-2);
}

int main(){
    cin>>n>>m;
    
    ll ans=1;
    for(ll i=n+1;i<=n+m;){
        ll lc=(ll)log2(i);
        ll gl=(1-inv(qsm(2,lc))+M)%M;//求一段区间内成功的概率
        ll r=min(n+m,(1ll<<(lc+1))-1);//区间的最右边 通过l找到右边的r
        ans=ans*qsm(gl,r-i+1)%M;//取一段区间
        i=r+1;//i指向下一段区间
    }
    cout<<ans;
	return 0;
} 
  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

CTGU-Yoghurt

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

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

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

打赏作者

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

抵扣说明:

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

余额充值