csansoon

P7.06 P85480 Pairs of a sequence (1)

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