Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "utils.h"
- #include <bitset>
- using namespace std;
- // GOAL: Find "family" of 8 primes separated only by the same kind of digit
- // 13, 23, 43, 53, 73, and 83
- // 56003, 56113, 56333, 56443, 56663, 56773, and 56993
- #define MAX 1000000
- #define FAM 8
- int main() {
- set<int> primes = sieve_primes(MAX);
- set<int> f;
- for (auto p = primes.begin(); p != primes.end(); ++p) {
- vector<int> vp = int_to_vect(*p);
- unordered_set<int> ud = unique_digits(*p);
- for (auto d = ud.begin(); d != ud.end(); ++d) {
- unordered_set<int> positions;
- for (int i = 0; i < vp.size(); i++) {
- if (vp[i] == *d) {
- positions.insert(i);
- }
- }
- vector<int> vpcp = vp;
- f.insert(*p);
- for (int i = 0; i <= 9; i++) {
- for (auto j = positions.begin(); j != positions.end(); ++j) {
- vpcp[*j] = i;
- }
- int n = vect_to_int(vpcp);
- if (primes.count(n) > 0 && num_digits(n) == num_digits(*p)) {
- f.insert(n);
- }
- }
- if (f.size() >= FAM) {
- for (auto num = f.begin(); num != f.end(); ++num) {
- cout << *num << ' ';
- }
- cout << endl;
- p = primes.end();
- break;
- }
- f.clear();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement