AC19,WA30,样例都过了
#include <bits/stdc++.h>
using namespace std;
#define space putchar(' ');
#define enter putchar('\n');
#define pb push_back
#define int long long
#define P 998244353
int read(){ char ch=getchar();int x=0,f=1;while(ch>'9' || ch<'0'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f; }
void print(int x){ if(x<0) putchar('-'),x=-x;if(x>9)print(x/10);putchar(x%10+'0'); }
int n,m,ans;
/*
011
000
001
010
011
100
101
110
111
*/
main()
{
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
cin>>n>>m;
n++;
int cnt=0;
while(m){
int x=m%2;
m>>=1;cnt++;
if(!x) continue;
int nn=n;
ans+=nn/(1ll<<cnt)*(1ll<<(cnt-1));ans%=P;
nn%=(1ll<<cnt)%P;
ans+=max(nn-(1ll<<(cnt-1)),0ll);ans%=P;
}
cout<<ans;
return 0;
}