Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <assert.h>
  4. #include <set>
  5. #include <map>
  6. #include <complex>
  7. #include <iostream>
  8. #include <time.h>
  9. #include <stack>
  10. #include <stdlib.h>
  11. #include <memory.h>
  12. #include <bitset>
  13. #include <math.h>
  14. #include <string>
  15. #include <string.h>
  16. #include <queue>
  17. #include <vector>
  18.  
  19. using namespace std;
  20.  
  21. const int MaxN = 3.2e7 + 10;
  22. const int MOD = 1e9 + 7;
  23. const int INF = 1e9;
  24.  
  25. int lp[MaxN], pr[MaxN / 10], sz;
  26.  
  27. bool prime(long long x) {
  28. if (x < MaxN) {
  29. return lp[x] == x;
  30. }
  31. for (int i = 0; i < sz && 1LL * pr[i] * pr[i] <= x; ++i) {
  32. if (x % pr[i] == 0) {
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38.  
  39. int main() {
  40. // freopen("input.txt", "r", stdin);
  41. for (int i = 2; i < MaxN; ++i) {
  42. if (!lp[i]) {
  43. lp[i] = pr[sz++] = i;
  44. }
  45. for (int j = 0; j < sz && i * pr[j] < MaxN && pr[j] <= lp[i]; ++j) {
  46. lp[i * pr[j]] = pr[j];
  47. }
  48. }
  49. long long a, b;
  50. cin >> a >> b;
  51. if (prime(b - a)) {
  52. cout << a << "->" << b << '\n';
  53. exit(0);
  54. }
  55. if (a == 3 && b == 7) {
  56. cout << a << "->" << a + 2 << "->" << b << '\n';
  57. exit(0);
  58. }
  59. if (a == 2) {
  60. if (prime(b + 2)) {
  61. cout << a << "->" << b + 2 << "->" << b << '\n';
  62. exit(0);
  63. }
  64. }
  65. if (prime(a - 2)) {
  66. if (prime(b - 2)) {
  67. cout << a << "->" << 2 << "->" << b << '\n';
  68. exit(0);
  69. }
  70. if (prime(b + 2)) {
  71. cout << a << "->" << 2 << "->" << b + 2 << "->" << b << '\n';
  72. exit(0);
  73. }
  74. }
  75. if (prime(a + 2)) {
  76. if (prime(b - 2)) {
  77. cout << a << "->" << a + 2 << "->" << 2 << "->" << b << '\n';
  78. exit(0);
  79. }
  80. if (prime(b + 2)) {
  81. cout << a << "->" << a + 2 << "->" << 2 << "->" << b + 2 << "->" << b << "\n";
  82. exit(0);
  83. }
  84. }
  85. cout << "Unlucky Benny\n";
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement