Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int a,b,n,m,d,x;
- bool ok;
- cin>>a>>b;
- if(a%2==b%2) ///am aceeasi paritate
- n=m=(a+b)/2;
- else
- {
- n=(a+b)/2;
- m=(a+b)/2+1;
- }
- x=0;
- while(n>=a && m<=b && x==0)
- {
- ///testez daca n este prim
- ok=1;
- if(n<2)ok=0;
- else for(d=2; d*d<=n&& ok==1; d++)
- if(n%d==0)ok=0;
- if(ok==1) x=n;
- else
- {///testez daca m este prim
- ok=1;
- if(m<2)ok=0;
- else for(d=2; d*d<=m&& ok==1; d++)
- if(m%d==0)ok=0;
- if(ok==1) x=m;
- }
- n--;m++;
- }
- if(x!=0)cout<<x;
- else cout<<"NU EXISTA";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement