karlangadas

Goldbach's Conjecture

Dec 23rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. const long long N =100000002;
  5. int esPrimo[N];
  6.  
  7. void criba(long long n){
  8.     for (long long i=0;i<=n;i++) esPrimo[i]=1;
  9.  
  10.     esPrimo[0]=esPrimo[1]=0;
  11.  
  12.     for (long long p=2;p<=n;p++){
  13.         if (esPrimo[p])
  14.             for(long long mul=p*p;mul<N;mul+=p) esPrimo[mul]=0;
  15.     }
  16. }
  17.  
  18. int main(){
  19.     criba(100000001);
  20.     int num;
  21.     while((cin>>num) && (num!=0)){
  22.         int encontrado=0,a=2;
  23.         while(!esPrimo[num-a]){
  24.             a++;
  25.             while(!esPrimo[a]) a++;
  26.         }
  27.         cout<<num<<" = "<<a<<" + "<<(num-a)<<endl;
  28.     }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment