Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- bool prime(int n) {
- for (int i = 2; i * i <= n; i++) if (!(n % i)) return false;
- return true;
- }
- signed main() {
- ios::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- for (int i = 1000; i <= 9999; i++) {
- if (prime(i)) {
- string s = to_string(i);
- sort(s.begin(), s.end());
- vector<int> v;
- do {
- if (s.starts_with('0')) continue;
- int n = stoi(s);
- if (prime(n)) {
- for (int i = 0; i < v.size(); i++) {
- for (int j = 0; j < i; j++) {
- if (v[i] - v[j] == n - v[i]) {
- cout << v[j] << v[i] << n << '\n';
- }
- }
- }
- v.push_back(n);
- }
- } while (next_permutation(s.begin(), s.end()));
- }
- }
- }
Advertisement