Advertisement
Anik_Akash

Goldbach and Euler

May 11th, 2021
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace    std;
  3. //             _   _                
  4. //   __ _ _   _| |_| |__   ___  _ __
  5. //  / _` | | | | __| '_ \ / _ \| '__|
  6. // | (_| | |_| | |_| | | | (_) | |  
  7. //  \__,_|\__,_|\__|_| |_|\___/|_|  
  8. //              _ _            _             _    
  9. //   __ _ _ __ (_) | __   __ _| | ____ _ ___| |__  
  10. //  / _` | '_ \| | |/ /  / _` | |/ / _` / __| '_ \
  11. // | (_| | | | | |   <  | (_| |   < (_| \__ \ | | |
  12. //  \__,_|_| |_|_|_|\_\  \__,_|_|\_\__,_|___/_| |_|
  13.  
  14.                                                
  15. #define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n')
  16. #define fasterio     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  17. #define NL           cout<<endl;
  18. #define pi           acos(-1.0) //3.1415926535897932384626
  19. #define dpoint(x)    fixed<<setprecision(x)
  20. #define debug(x)     cout<<x<<endl;
  21. #define gcd(a,b)     __gcd(a,b);
  22. #define lcm(x,y)     (a * (b / gcd(a, b)));
  23. #define pb           push_back
  24. #define mx          100000005
  25.  
  26. typedef long long int       ll;
  27. typedef double              dl;
  28. typedef unsigned long long  ul;
  29.  
  30. // --------------------------Pre made Functions & Proto Type--------------------------//
  31. template <class T> T digitsum(T n){T sum=0;while(n!=0){sum+=n%10;n/=10;}return sum;}
  32. bool prime[mx];
  33. void sieve()
  34. {
  35.     memset(prime, true, sizeof(prime));
  36.     for(ll i = 4; i<mx; i+=2)prime[i]=false;
  37.         prime[0]=false;
  38.     for(ll i=3; i*i<=mx; i+=2)
  39.     {
  40.         if(prime[i])
  41.         {
  42.             for(ll j=i*i; j<mx; j+=2*i)prime[j]=false;
  43.         }
  44.     }
  45.  
  46.  
  47. }
  48.  
  49. int main()
  50. {
  51.     #ifdef EXTRA_8
  52.         clock_t tStart = clock();
  53.         freopen("input.txt","r",stdin);
  54.         freopen("out.txt","w",stdout);
  55.     #endif
  56.      sieve();
  57.      ll n;
  58.      while(scanf("%lld",&n)==1)
  59.      {
  60.         if(n & 1)
  61.         {
  62.             if(prime[n-2])printf("%lld is the sum of 2 and %lld.\n",n, n-2 );
  63.             else printf("%lld is not the sum of two primes!\n",n);
  64.         }
  65.         else
  66.         {
  67.             bool flg = true;
  68.             for(ll i = n/2-1; i>=0; i--)
  69.             {
  70.                 if(prime[i] && prime[n-i])
  71.                 {
  72.                     printf("%lld is the sum of %lld and %lld.\n",n, i, n-i );
  73.                     flg = false;
  74.                     break;
  75.                 }
  76.             }
  77.             if(flg)printf("%lld is not the sum of two primes!\n",n);
  78.         }
  79.      }
  80.      
  81.        
  82.     #ifdef EXTRA_8
  83.         fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  84.     #endif
  85.     return 0;
  86. }
  87.  
  88.  
  89.  
  90.  
  91. //  _____            _   _            _                      ___   __
  92. // |  ___|__  _ __  | |_| |__   ___  | |    _____   _____   / _ \ / _|
  93. // | |_ / _ \| '__| | __| '_ \ / _ \ | |   / _ \ \ / / _ \ | | | | |_
  94. // |  _| (_) | |    | |_| | | |  __/ | |__| (_) \ V /  __/ | |_| |  _|
  95. // |_|  \___/|_|     \__|_| |_|\___| |_____\___/ \_/ \___|  \___/|_|                                                                    
  96. //   ____ ____  
  97. //  / ___|  _ \
  98. // | |   | |_) |
  99. // | |___|  __/
  100. //  \____|_|    
  101. //            
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement