小红定义一个数组是好数组,当且仅当所有长度为 3 的连续子数组的元素和为偶数。 现在小红希望你求出,长度为,且所有元素均为不超过的正整数的好数组数量。 由于答案可能过大,请对取模。
区块链毕设网qklbishe.com为您提供问题的解答
小红定义一个数组是好数组,当且仅当所有长度为 3 的连续子数组的元素和为偶数。
现在小红希望你求出,长度为,且所有元素均为不超过
的正整数的好数组数量。
由于答案可能过大,请对取模。
#include <iostream> #include <vector> #include <string> #include <algorithm> constexpr const int mod = 1e9 + 7; long long FastPow(int a, int p){ // p >= 1 long long tmp = a, res = 1; while(p){ if(p&1){ res *= tmp; res %= mod; } p = p >> 1; tmp *= tmp; tmp %= mod; } return res; } int main() { int n, k; std::cin >> n >> k; long long ans = 0; // 总共就是样例的4种循环模式,分别计算奇偶数 ans += FastPow((k + 1) / 2, (2 * n + 2) / 3) % mod * FastPow(k / 2, n / 3) % mod; ans %= mod; ans += FastPow((k + 1) / 2, (2 * n) / 3) % mod * FastPow(k / 2, (n + 2) / 3) % mod; ans %= mod; ans += FastPow((k + 1) / 2, (2 * n + 1) / 3) % mod * FastPow(k / 2, (n + 1) / 3) % mod; ans %= mod; ans += FastPow(k / 2, n); ans %= mod; std::cout << ans; }
19:37
以上就是关于问题小红定义一个数组是好数组,当且仅当所有长度为 3 的连续子数组的元素和为偶数。
现在小红希望你求出,长度为,且所有元素均为不超过的正整数的好数组数量。
由于答案可能过大,请对取模。的答案
欢迎关注区块链毕设网-
web3一级市场套利打新赚钱空投教程
区块链NFT链游项目方科学家脚本开发培训