 #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;
}