思路应该是对的,但是后两个点错了。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int n, q;
int spow(int a, int b)
{
int ans = 1, base = a;
while(b > 0)
{
if(b & 1) ans = ans * base % mod;
base = base * base % mod;
b >>= 1LL;
}
return ans % mod;
}
int slog(int a)
{
if (a == 0)
{
return n;
}
int cnt = 0;
while (a % 2 == 0)
{
cnt ++;
a /= 2;
}
return cnt;
}
signed main()
{
scanf("%lld %lld", &n, &q);
while (q --)
{
int x, y;
scanf("%lld %lld", &x, &y);
x ++;
x = (int)ceil(x / (spow(2, y) * 1.0)) % mod;
if(y > 64)
{
cout << spow(2, n) - 1 << "\n";
continue;
}
for (int i = 1; i <= y; i ++)
{
if (x % 2 == 0)
{
x = x * 2 % mod;
}
else
{
x = x * 2 % mod, x --;
}
}
if (x % 2 == 0)
{
printf("%lld\n", spow(2, slog(x)) - 1);
}
else if (x % 2 == 1)
{
printf("%lld\n", spow(2, slog(x - 1)) - 1);
}
}
return 0;
}