Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <algorithm>
- #include <assert.h>
- #include <set>
- #include <map>
- #include <complex>
- #include <iostream>
- #include <time.h>
- #include <stack>
- #include <stdlib.h>
- #include <memory.h>
- #include <bitset>
- #include <math.h>
- #include <string>
- #include <string.h>
- #include <queue>
- #include <vector>
- using namespace std;
- const int MaxN = 3.2e7 + 10;
- const int MOD = 1e9 + 7;
- const int INF = 1e9;
- int lp[MaxN], pr[MaxN / 10], sz;
- bool prime(long long x) {
- if (x < MaxN) {
- return lp[x] == x;
- }
- for (int i = 0; i < sz && 1LL * pr[i] * pr[i] <= x; ++i) {
- if (x % pr[i] == 0) {
- return false;
- }
- }
- return true;
- }
- int main() {
- // freopen("input.txt", "r", stdin);
- for (int i = 2; i < MaxN; ++i) {
- if (!lp[i]) {
- lp[i] = pr[sz++] = i;
- }
- for (int j = 0; j < sz && i * pr[j] < MaxN && pr[j] <= lp[i]; ++j) {
- lp[i * pr[j]] = pr[j];
- }
- }
- long long a, b;
- cin >> a >> b;
- if (prime(b - a)) {
- cout << a << "->" << b << '\n';
- exit(0);
- }
- if (a == 3 && b == 7) {
- cout << a << "->" << a + 2 << "->" << b << '\n';
- exit(0);
- }
- if (a == 2) {
- if (prime(b + 2)) {
- cout << a << "->" << b + 2 << "->" << b << '\n';
- exit(0);
- }
- }
- if (prime(a - 2)) {
- if (prime(b - 2)) {
- cout << a << "->" << 2 << "->" << b << '\n';
- exit(0);
- }
- if (prime(b + 2)) {
- cout << a << "->" << 2 << "->" << b + 2 << "->" << b << '\n';
- exit(0);
- }
- }
- if (prime(a + 2)) {
- if (prime(b - 2)) {
- cout << a << "->" << a + 2 << "->" << 2 << "->" << b << '\n';
- exit(0);
- }
- if (prime(b + 2)) {
- cout << a << "->" << a + 2 << "->" << 2 << "->" << b + 2 << "->" << b << "\n";
- exit(0);
- }
- }
- cout << "Unlucky Benny\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement