Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isPrime(int x) {
- for (int i = 2; i < x; i++) {
- if (x % i == 0) {
- return false;
- }
- }
- return true;
- }
- bool isInteresting(string s) {
- int cnt = count(s.begin(), s.end(), '0');
- if (cnt > 0) return false;
- for (int i = 0; i < s.size(); i++) {
- for (int j = i + 1; j < s.size(); j++) {
- int a = s[i] - '0';
- int b = s[j] - '0';
- if (__gcd(a, b) != 1 || !isPrime(a + b)) {
- return false;
- }
- }
- }
- return true;
- }
- int main(){
- int n;
- cin >> n;
- vector <string> vec;
- for (int i = 11; i <= 99; i++) {
- string x = to_string(i);
- if (isInteresting(x)) {
- vec.push_back(x);
- }
- }
- for (int i = 0; vec.size() <= n; i++) {
- string s = vec[i];
- for (char d = '1'; d <= '9'; d++) {
- if (isInteresting(s + d)) {
- vec.push_back(s + d);
- }
- }
- }
- cout << vec[n - 1] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement