Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int i_prim(int x)
- {
- int i;
- for (i=2;i<=sqrt(x);i++)
- if (x%i==0)
- return 0;
- return 1;
- }
- int diferenta()
- {
- int p1,p2,i,n;
- cin>>n;
- if(i_prim(n)==1)
- return 0;
- p1=n-1;
- while (i_prim(p1)==0)
- p1--;
- p2=n+1;
- while (i-prim(p1)==0)
- p2++;
- return p2-p1;
- }
- int main()
- {
- cout<<diferenta();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement