fork download
  1. // --------------------------------------------------<TEMPLATE>--------------------------------------------------
  2. // --------------------<optimizations>--------------------
  3. #pragma GCC optimize("O3")
  4. //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
  5. #pragma comment(linker, "/stack:200000000")
  6. //(UNCOMMENT WHEN NEEDED)\
  7. #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")\
  8. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  9. // -------------------</optimizations>--------------------
  10.  
  11. // ---------------<Headers and namespaces>----------------
  12. #include<bits/stdc++.h>
  13. #include <ext/pb_ds/assoc_container.hpp>
  14. using namespace std;
  15. using namespace __gnu_pbds;
  16. #define mod 1000000007
  17. #define int long long
  18. #define lcm(a, b) (a/__gcd(a, b))*b
  19. #define endl '\n'
  20. #define cntbits(x) __builtin_popcountll(x)
  21. #define cntzero(x) __builtin_ctzll(x) //count the number of zeros before the first occurence of '1' form right
  22. #define mk(arr, n, type) type *arr=new type[n]
  23. #define vi vector<int>
  24. #define mp make_pair
  25. #define pi pair<int,int>
  26. #define vc vector<char>
  27. #define pb push_back
  28. #define F first
  29. #define S second
  30. #define w(x) int x; cin >> x; while(x--)
  31. #define in(arr, n) for(int i=0; i<n; i++) cin >> arr[i];
  32. #define deb(x) cout<< #x << " " << x << "\n";
  33. #define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << "\n";
  34. #define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";
  35. #define PI 3.1415926535897932384626
  36. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //shuffle(arr, arr+n, rng);
  37.  
  38. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  39.  
  40. /**
  41.  * Limits in C++ for reference
  42.  * _____________________________________________________________________________________
  43.  * |Sr| Macro Name | Description | Value
  44.  * |No|____________|_________________________________|__________________________________
  45.  * |1.| ULLONG_MAX | Maximum value unsigned long long| 18,446,744,073,709,551,615 (10^20)
  46.  * |2.| LLONG_MAX | Maximum value long long | 9,223,372,036,854,775,807 (10^19)
  47.  * |3.| LLONG_MIN | Minimum value long long |-9,223,372,036,854,775,808 -1*(10^19)
  48.  * |4.| INT_MAX | Maximum value int | 2,147,483,647 (10^10)
  49.  * |5.| INT_MIN | Minimum value int |-2,147,483,648 (10^10)
  50. */
  51.  
  52. void c_p_c()
  53. {
  54. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  55. #ifndef ONLINE_JUDGE
  56. freopen("input.txt", "r", stdin);
  57. freopen("output.txt", "w", stdout);
  58. #endif
  59. }
  60.  
  61. bool isPrime[10005];
  62.  
  63. void Seive()
  64. {
  65. for (int i = 3; i <= 10005; i += 2)
  66. {
  67. isPrime[i] = true;
  68. }
  69.  
  70. for (int i = 3; i <= 10005; i += 2)
  71. {
  72. if (isPrime[i])
  73. {
  74. for (int j = i * i; j <= 10005; j += i)
  75. {
  76. isPrime[j] = false;
  77. }
  78. }
  79. }
  80.  
  81. isPrime[2] = 1;
  82. isPrime[0] = isPrime[1] = 0;
  83. }
  84.  
  85. int fib(int a, int b, int num_terms)
  86. {
  87. int i = a, j = b;
  88. int c;
  89. for (int z = 3; z <= num_terms; z++)
  90. {
  91. c = i + j;
  92. i = j;
  93. j = c;
  94. }
  95. return c;
  96. }
  97.  
  98.  
  99. int32_t main()
  100. {
  101. c_p_c();
  102. Seive();
  103. //clock_t begin, end; double time_spent;
  104. //begin = clock();
  105.  
  106. int a, b; cin >> a >> b;
  107. vi primes;
  108. for (int i = a; i <= b; i++)
  109. {
  110. if (isPrime[i])
  111. {
  112. primes.pb(i);
  113. }
  114. }
  115. set<int> pp;
  116.  
  117. for (int i = 0; i < primes.size(); i++)
  118. {
  119. for (int j = 0; j < primes.size(); j++)
  120. {
  121. if (primes[i] != primes[j])
  122. {
  123. string a = "";
  124. a += to_string(primes[i]);
  125. a += to_string(primes[j]);
  126. int z = stoi(a);
  127. if (isPrime[z])
  128. {
  129. pp.insert(z);
  130. }
  131. }
  132. }
  133. }
  134. int c = *pp.begin();
  135. int d = *pp.rbegin();
  136. int num_of_terms = pp.size();
  137. cout << fib(c, d, num_of_terms) << endl;
  138.  
  139. //end = clock();
  140. //time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  141. //cout << "Time spent = " << time_spent << endl;
  142. return 0;
  143. }
Success #stdin #stdout 0s 4564KB
stdin
30 70
stdout
2027041