Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <bits/stdc++.h>
using namespace std;
bool prime(long n) {
if (n < 2) return false;
for (long i = 2; i*i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
using Candidates = vector<pair<long, long>>;
Candidates candidates(long n) {
Candidates v;
string s = to_string(n);
size_t length = s.length();
for (int i = 1; i < s.length(); i++) {
if (s[i] != '0') {
v.push_back(make_pair(
stol(s.substr(0, i)),
stol(s.substr(i, length-i))
));
}
}
return v;
}
bool is_double(long n) {
if (n < 10) return false;
for (auto i : candidates(n)) {
if (prime(i.first) && prime(i.second)) {
return true;
}
}
return false;
}
int main() {
long n;
cin >> n;
printf(is_double(n) ? "TAK\n" : "NIE\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment