Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "EULER"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- int m, primes[N], f[N];
- // O(n) Prime Sieve
- void Prepare()
- {
- for (int i = 2; i < N; ++i)
- {
- if (!f[i])
- f[i] = primes[++m] = i;
- for (int j = 1; j <= m && primes[j] * i < N; ++j)
- f[primes[j] * i] = primes[j];
- }
- }
- // Prime Checker
- bool IsPrime(int v)
- {
- if (v < 2)
- return false;
- if (v % 2 == 0)
- return v == 2;
- for (int i = 2; primes[i] * primes[i] <= v; ++i)
- if (v % primes[i] == 0)
- return false;
- return true;
- }
- void Solve()
- {
- int t;
- cin >> t;
- while (t--)
- {
- int n;
- cin >> n;
- for (int i = 1; i <= m && primes[i] <= n; ++i)
- if (IsPrime(n - primes[i])) // Số còn lại có phải số nguyên tố
- {
- cout << primes[i] << " " << n - primes[i] << '\n';
- break;
- }
- }
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Prepare();
- Solve();
- }
Add Comment
Please, Sign In to add comment