Created
November 16, 2017 15:31
-
-
Save sheerun/7feb000de4bcb7dcc83fe8a9f8287c3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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