对于1< = N< = 1000000000,我需要计算2N mod 1000000007,它必须非常快!
我目前的做法是:
我目前的做法是:
ull power_of_2_mod(ull n) { ull result = 1; if (n <= 63) { result <<= n; result = result % 1000000007; } else { ull one = 1; one <<= 63; while (n > 63) { result = ((result % 1000000007) * (one % 1000000007)) % 1000000007; n -= 63; } for (int i = 1; i <= n; ++i) { result = (result * 2) % 1000000007; } } return result; }
但它似乎不够快.任何的想法?