洗牌
2025-11-23 19:44:19
发布于:浙江
9阅读
0回复
0点赞
#include <iostream>
using namespace std;
typedef long long ll;
ll pow_rev(ll N, ll t, ll pos) {
ll k = N / 2;
for (ll step = 0; step < (1LL << t); ++step) {
if (pos % 2 == 1) {
pos = k + (pos + 1) / 2;
} else {
pos = pos / 2;
}
}
return pos;
}
ll find_original(ll N, ll M, ll L) {
ll pos = L;
ll t = 0;
while (M > 0) {
if (M & 1) {
pos = pow_rev(N, t, pos);
}
M >>= 1; // M = M / 2
t++;
}
return pos;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N, M, L;
cin >> N >> M >> L;
cout << find_original(N, M, L) << '\n';
return 0;
}
这里空空如也

有帮助,赞一个