#include<bits/stdc++.h>
using namespace std;
bool is_prime(int k) {
if(k < 2) return 0;
for(int i = 2; i <= sqrt(k); i++)
if(k % i == 0) return 0;
return 1;
}
bool check_prime(int k) {
if(is_prime(k)) return 1;
return 0;
}
bool check_sum_prime(int k) {
int s = 0;
while(k != 0){
s += k % 10;
k /= 10;
}
if(is_prime(s)) return 1;
return 0;
}
bool check_element(int k) {
while(k != 0) {
if(!is_prime(k % 10)) return 0;
k /= 10;
}
return 1;
}
bool check_n(int k, int n) {
int d = 0;
while(k != 0) {
k /= 10;
d++;
}
if(d == n) return 1;
return 0;
}
int main() {
int k, n;
cin >> k >> n;
if(check_n(k, n)) if(check_prime(k)) if(check_sum_prime(k))
if(check_element(k)) {
cout << k << " thoa man dieu kien";
return 0;
}
cout << k << " khong thoa man dieu kien";
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKYm9vbCBpc19wcmltZShpbnQgaykgewoJaWYoayA8IDIpIHJldHVybiAwOwoJZm9yKGludCBpID0gMjsgaSA8PSBzcXJ0KGspOyBpKyspCgkJaWYoayAlIGkgPT0gMCkgcmV0dXJuIDA7CglyZXR1cm4gMTsKfQpib29sIGNoZWNrX3ByaW1lKGludCBrKSB7CglpZihpc19wcmltZShrKSkgcmV0dXJuIDE7CglyZXR1cm4gMDsKfQpib29sIGNoZWNrX3N1bV9wcmltZShpbnQgaykgewoJaW50ICBzID0gMDsKCXdoaWxlKGsgIT0gMCl7IAoJCXMgKz0gayAlIDEwOyAKCQlrIC89IDEwOwoJfQoJaWYoaXNfcHJpbWUocykpIHJldHVybiAxOwoJcmV0dXJuIDA7Cn0KYm9vbCBjaGVja19lbGVtZW50KGludCBrKSB7Cgl3aGlsZShrICE9IDApIHsKCQlpZighaXNfcHJpbWUoayAlIDEwKSkgcmV0dXJuIDA7CgkJayAvPSAxMDsKCX0KCXJldHVybiAxOwp9CmJvb2wgY2hlY2tfbihpbnQgaywgaW50IG4pIHsKCWludCBkID0gMDsKCXdoaWxlKGsgIT0gMCkgewoJCWsgLz0gMTA7CgkJZCsrOwoJfQoJaWYoZCA9PSBuKSByZXR1cm4gMTsKCXJldHVybiAwOwp9CmludCBtYWluKCkgewoJaW50IGssIG47CgljaW4gPj4gayA+PiBuOwoJaWYoY2hlY2tfbihrLCBuKSkgaWYoY2hlY2tfcHJpbWUoaykpCWlmKGNoZWNrX3N1bV9wcmltZShrKSkgCglpZihjaGVja19lbGVtZW50KGspKSB7CgkJY291dCA8PCBrIDw8ICIgdGhvYSBtYW4gZGlldSBraWVuIjsKCQlyZXR1cm4gMDsKCX0KCWNvdXQgPDwgayA8PCAiIGtob25nIHRob2EgbWFuIGRpZXUga2llbiI7Cn0=