注意看代码的最外层while循环的条件
while (o && i > 0) {
if (o >= book[i]) {
o -= book[i];
t = i;
while (book[i] > 0) {
if (book[i] & 1) {
ans *= t;
ans %= mod;
}
t = t * t;
t %= mod;
book[i] >>= 1;
}
} else {
t = i;
while (o > 0) {
if (o & 1) {
ans *= t;
ans %= mod;
}
t = t * t;
t %= mod;
o >>= 1;
}
}
i -= 2;
}
如果你写成了
while (o && i) {
那就完了
因为i一直是奇数,只会从1变成-1,不存在变为0的情况