Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int NMAX = 12500000;
- bool primes[NMAX];
- inline void precompute()
- {
- memset(primes, true, sizeof(primes));
- primes[1] = primes[0] = false;
- for (int i = 1; i * i <= NMAX; i++)
- if (primes[i])
- {
- for (int j = i * i; j <= NMAX; j += i)
- primes[j] = false;
- }
- }
- bool used[NMAX];
- inline void solve(const int n)
- {
- for (int i = 1; i < n * 2; i++)
- if (!used[i])
- {
- for (int j = i + 1; j <= n * 2; j++)
- if (!used[j])
- {
- int sum = i * i + j * j;
- if (primes[sum])
- {
- used[j] = true;
- cout << i << ' ' << j << '\n';
- break;
- }
- }
- }
- }
- int main()
- {
- freopen("perechi.in", "r", stdin);
- freopen("perechi.out", "w", stdout);
- int n;
- cin >> n;
- precompute();
- solve(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement