Advertisement
nicuvlad76

Untitled

Nov 20th, 2020
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a,b,n,m,d,x;
  6.     bool ok;
  7.     cin>>a>>b;
  8.     if(a%2==b%2) ///am aceeasi paritate
  9.         n=m=(a+b)/2;
  10.     else
  11.     {
  12.         n=(a+b)/2;
  13.         m=(a+b)/2+1;
  14.     }
  15.     x=0;
  16.     while(n>=a && m<=b && x==0)
  17.     {
  18.         ///testez daca n este prim
  19.         ok=1;
  20.         if(n<2)ok=0;
  21.         else for(d=2; d*d<=n&& ok==1; d++)
  22.                 if(n%d==0)ok=0;
  23.         if(ok==1) x=n;
  24.         else
  25.         {///testez daca m este prim
  26.             ok=1;
  27.             if(m<2)ok=0;
  28.             else for(d=2; d*d<=m&& ok==1; d++)
  29.                     if(m%d==0)ok=0;
  30.             if(ok==1) x=m;
  31.         }
  32.         n--;m++;
  33.     }
  34.     if(x!=0)cout<<x;
  35.     else cout<<"NU EXISTA";
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement