为什么这个代码只通过了 J 题 90% 的用例?
#include <iostream> #include <vector> using namespace std; using LL = long long; const LL MODULO = 998244353; vector<LL> values, counts; LL max_lose(LL n) { LL result = 0; ++n; while (n > 1) { n >>= 1; ++result; } return result; } LL seg_lower(LL lose_max) { return (1LL << lose_max) - 1; } LL seg_upper(LL lose_max) { return (2LL << lose_max) - 1; } LL fast_pow(LL base, LL exponent) { LL result = 1 % MODULO, multiplier = base % MODULO; while (exponent > 0) { if ((exponent & 1) == 1) result = result * multiplier % MODULO; multiplier = multiplier * multiplier % MODULO; exponent >>= 1; } return result; } int main() { LL n = 0, m = 0; LL prob_mod = 0; cin >> n >> m; for (LL i = max_lose(n); seg_lower(i) < n + m; ++i) { values.push_back(i); if (n >= seg_lower(i) && n < seg_upper(i)) counts.push_back(seg_upper(i) - n); else if (n + m >= seg_lower(i) && n + m < seg_upper(i)) counts.push_back(n + m - seg_lower(i)); else counts.push_back(seg_upper(i) - seg_lower(i)); } prob_mod = 1; for (LL i = 0; i < values.size(); ++i) { LL den = 0, numer = 0; den = fast_pow((fast_pow(2, values[i]) - 1 + MODULO) % MODULO, counts[i]); numer = fast_pow(2, values[i] * counts[i]); prob_mod = prob_mod * den % MODULO * fast_pow(numer, MODULO - 2) % MODULO; } cout << prob_mod << '\n'; return 0; }
为什么这个代码只通过了 J 题 的用例?