#include <iostream> int main() { int n, m, last, res = 0; std::cin >> n >> m; res = m; for (int i=0; i<n; i++) { if (i%2) res *= m-1; else res *= m; } res += m; std::cout << res; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> int main() { int n, m, last, res = 0; std::cin >> n >> m; res = m; for (int i=0; i<n; i++) { if (i%2) res *= m-1; else res *= m; } res += m; std::cout << res; return 0; } |