Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <utility>
- using namespace std;
- bool IsPrime(int n) {
- if (n == 2) return true;
- if (n % 2 == 0) return false;
- for (int i = 3; i * i <= n; i += 2) {
- if (n % i == 0) return false;
- }
- return true;
- }
- void main() {
- set<int> good_sums;
- // Operations done by second wiseman.
- for (int a = 2; a <= 100; ++a) {
- for (int b = 2; b <= 100; ++b) {
- int sum = a + b;
- int mul = a * b;
- bool good_sum = true;
- for (int a2 = 2; a2 <= sum - 2; ++a2) {
- int b2 = sum - a2;
- if (IsPrime(a2) && IsPrime(b2)) {
- good_sum = false;
- //std::cout << "a2 = " << a2 << ", b2 = " << b2 << std::endl;
- }
- }
- if (good_sum) {
- good_sums.insert(sum);
- }
- }
- }
- cout << "GoodSums" << endl;
- for (auto it = good_sums.begin(); it != good_sums.end(); ++it) {
- cout << *it << " ";
- }
- cout << endl;
- // Operations done by second wiseman.
- set<int> good_muls;
- for (int a_1 = 2; a_1 <= 100; ++a_1) {
- for (int a_2 = 2; a_2 <= 100; ++a_2) {
- if (!IsPrime(a_1) || !IsPrime(a_2)) continue;
- int a1 = a_1 * a_2;
- if (a1 > 100) continue;
- for (int b1 = 2; b1 <= 100 - a1; ++b1) {
- if (!IsPrime(b1)) continue;
- if (b1 * a_2 > 100) continue;
- if ((good_sums.count(a1 + b1) > 0 && good_sums.count(a_1 + b1 * a_2) == 0 && good_sums.count(a_2 + b1 * a_1) == 0) ||
- (good_sums.count(a1 + b1) == 0 && good_sums.count(a_1 + b1 * a_2) > 0 && good_sums.count(a_2 + b1 * a_1) == 0) ||
- (good_sums.count(a1 + b1) == 0 && good_sums.count(a_1 + b1 * a_2) == 0 && good_sums.count(a_2 + b1 * a_1) > 0)) {
- good_muls.insert(a1 * b1);
- }
- }
- }
- }
- cout << "Answers" << endl;
- for (auto it = good_sums.begin(); it != good_sums.end(); ++it) {
- int good_muls_count = 0;
- int ans_a = 0, ans_b = 0;
- for (auto a2 = 2; a2 <= *it - 2; ++a2) {
- int b2 = *it - a2;
- if (a2 > b2 || a2 > 100 || b2 > 100) continue;
- if (good_muls.count(a2 * b2) > 0) {
- ++good_muls_count;
- ans_a = a2, ans_b = b2;
- }
- }
- if (good_muls_count == 1) {
- cout << "a = " << ans_a << ", b = " << ans_b << ", sum = " << (ans_a + ans_b) << ", mul = " << (ans_a * ans_b) << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment