fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. // #define int long long int
  5. #define ld long double
  6. #define all(x) x.begin(), x.end()
  7. #define sortall(x) sort(all(x))
  8. #define endl '\n'
  9. #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  10. template<class T>
  11. void printC (T Collection)
  12. {
  13. for (auto&i:Collection)
  14. cout << i << " \n";
  15. cout << '\n';
  16. }
  17.  
  18. /*
  19.  * Think twice, code once
  20.  * Think of different approaches to tackle a problem: write them down.
  21.  * Think of different views of the problem. don't look from only one side.
  22.  * don't get stuck in one approach.
  23.  * common mistakes: - over_flow
  24.  * - out_of_bound index
  25.  * - infinite loop
  26.  * - corner cases
  27.  * - duplication counting.
  28. */
  29.  
  30. vector<bool> sieve()
  31. {
  32. vector<bool> isPrime(1e6+1, true);
  33. isPrime[0] = isPrime[1] = false;
  34. for (int i = 2; i * i <= 1e6; ++i)
  35. if (isPrime[i])
  36. for (int j = i * i; j <= 1e6; j += i)
  37. isPrime[j] = false;
  38. return isPrime;
  39. }
  40.  
  41. void solve()
  42. {
  43. vector<bool> isPrime(sieve());
  44. int q;
  45. while (cin >> q && q != 0)
  46. {
  47. bool flag = true;
  48. for (int i = 3; i < isPrime.size(); i += 2)
  49. {
  50. if (isPrime[i] && isPrime[q-i])
  51. {
  52. cout << q << " = " << i << " + " << q-i << '\n';
  53. flag = false;
  54. break;
  55. }
  56. }
  57. if (flag)
  58. cout << "Goldbach's conjecture is wrong.\n";
  59. }
  60. }
  61.  
  62. int main()
  63. {
  64. #ifndef ONLINE_JUDGE
  65. freopen("input.txt", "r", stdin);
  66. freopen("output.txt", "w", stdout);
  67. freopen("Errors.txt", "w", stderr);
  68. #endif
  69. fast
  70. int t = 1;
  71. // cin >> t;
  72. while (t--)
  73. {
  74. solve();
  75. if (t) cout << '\n';
  76. }
  77. cout << '\n';
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout