#include <iostream>
int potega (int x, int n) {
if (n == 0)
return 1;
return x * potega(x, n - 1);
}
int main() {
int n, B, m, d, suma;
std::cin >> n >> B;
m = n;
d = 0;
while(m > 0) {
m /= B;
++d;
}
m = n;
suma = 0;
while(m > 0) {
suma += potega(m % B, d);
m /= B;
}
std::cout << suma << std::endl
<< ((suma==n) ? "TAK" : "NIE") << std::endl;
return 0;
}
ICNpbmNsdWRlIDxpb3N0cmVhbT4KIAogaW50IHBvdGVnYSAoaW50IHgsIGludCBuKSB7CiAJaWYgKG4gPT0gMCkKIAkJcmV0dXJuIDE7CiAJcmV0dXJuIHggKiBwb3RlZ2EoeCwgbiAtIDEpOwogfQogCiBpbnQgbWFpbigpIHsKIAlpbnQgbiwgQiwgbSwgZCwgc3VtYTsKIAlzdGQ6OmNpbiA+PiBuID4+IEI7CiAJbSA9IG47CiAJZCA9IDA7CiAJd2hpbGUobSA+IDApIHsKIAkJbSAvPSBCOwogCQkrK2Q7CiAJfQogCW0gPSBuOwogCXN1bWEgPSAwOwogCXdoaWxlKG0gPiAwKSB7CiAJCXN1bWEgKz0gcG90ZWdhKG0gJSBCLCBkKTsKIAkJbSAvPSBCOwogCX0KIAlzdGQ6OmNvdXQgPDwgc3VtYSA8PCBzdGQ6OmVuZGwKIAkJPDwgKChzdW1hPT1uKSA/ICJUQUsiIDogIk5JRSIpIDw8IHN0ZDo6ZW5kbDsKIAlyZXR1cm4gMDsKfQ==