Masked Popcount 题解
背景
罚了一发,太菜了。为什么我终于有时间的时候她要考试?
题意
给你
其中
分析
两个数字在二进制下根据数据范围有
先把
我们可以先看一下:
000
001
010
011
100
101
110
111
容易得到规律:数位
因此可以得到算法:计算
Code
#include<bits/stdc++.h>
//#include<atcoder/modint>
#define int long long
using namespace std;
//using mint=atcoder::modint998244353;
inline int read()
{
int w=1,s=0;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch)){s=s*10+(ch-'0');ch=getchar();}
return w*s;
}
const int maxn=1e6+10;
int mod=998244353;
int n,m;
int ans=0;
int cntm[maxn],totm;
void pre(int x)
{
while(x)
{
int t=x%2;
if(t)cntm[++totm]=1;
else cntm[++totm]=0;
x>>=1;
}
}
signed main()
{
// freopen("xxx.in","r",stdin);
// freopen("xxx.out","w",stdout);
cin>>n>>m;
if(n==0||m==0)return 0*printf("0");
pre(m);
for(int i=1;i<=totm;i++)
{
if(!cntm[i])continue;
int qw=pow(2,i-1),xun=pow(2,i);
ans=(ans+qw*((n+1)/xun))%mod;
int nn=(n+1)%xun;
if(nn>xun/2)ans=(ans+nn-xun/2)%mod;
}
cout<<ans%mod;
return 0;
}
完结撒花
分类:
题解合集
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】