#include <iostream>
#include <cmath>
#include <cstdlib>
int getWrongMoves(int n, int k)
{
int result = 1;
for (int i = 1; i < n - k; ++i)
{
result = 2 * result + i;
}
return result;
}
int main(int argc, char *argv[])
{
int n = 5;
int k = 2;
if (argc > 2)
{
n = atoi(argv[1]);
k = atoi(argv[2])+1;
}
if (n < 1 || n > 100)
{
std::cout << "Usage: zenik <N>, <K>\n"
" where 1 <= N, K <= 100" << std::endl;
return 0;
}
double allMoves = std::pow(2, n-1);
double wrongMoves = 0;
if (k == 1)
{
wrongMoves = allMoves - 1;
}
else if (k >= n)
{
wrongMoves = 0;
}
else
{
wrongMoves = getWrongMoves(n, k);
}
std::cout << "all moves: " << allMoves << std::endl;
std::cout << "wrong moves: " << wrongMoves << std::endl;
std::cout << "corect moves: " << allMoves - wrongMoves << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0ZGxpYj4KIAppbnQgZ2V0V3JvbmdNb3ZlcyhpbnQgbiwgaW50IGspCnsKICAgIGludCByZXN1bHQgPSAxOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBuIC0gazsgKytpKQogICAgewogICAgICAgIHJlc3VsdCA9IDIgKiByZXN1bHQgKyBpOwogICAgfQogICAgcmV0dXJuICByZXN1bHQ7Cn0KIAppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgICBpbnQgbiA9IDU7CiAgICBpbnQgayA9IDI7CiAKICAgIGlmIChhcmdjID4gMikKICAgIHsKICAgICAgICBuID0gYXRvaShhcmd2WzFdKTsKICAgICAgICBrID0gYXRvaShhcmd2WzJdKSsxOwogICAgfQogICAgaWYgKG4gPCAxIHx8IG4gPiAxMDApCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJVc2FnZTogemVuaWsgPE4+LCA8Sz5cbiIKICAgICAgICAgICAgICAgICAgIiB3aGVyZSAxIDw9IE4sIEsgPD0gMTAw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