Advertisement
dyamondz

Parells d'una seqüència (1) - P85480

Nov 15th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. bool esPrimer(int a){
  6.     if(a==0 || a==1) return false;
  7.     else{
  8.         for(int i=2;i*i<=a;++i){
  9.             if(a%i==0) return false;
  10.         }
  11.         return true;
  12.     }
  13. }
  14.  
  15. int main(){
  16.     int n;
  17.     while(cin>>n){
  18.         if(n>0){
  19.             vector <int> A(n,0);
  20.             for(int i=0;i<A.size();++i) cin>>A[i];
  21.             bool trobat=false;
  22.             int i=0,j=0;
  23.             while(!trobat && i<A.size()-1){
  24.                     j=i+1;
  25.                 while(!trobat && j<A.size()){
  26.                     if(esPrimer(A[i]+A[j])) trobat=true;
  27.                     else ++j;
  28.                 }
  29.                 ++i;
  30.             }
  31.             if(trobat) cout<<"si"<<endl;
  32.             else cout<<"no"<<endl;
  33.         }
  34.         else cout<<"no"<<endl;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement