Advertisement
icatalin

varianta 2

Nov 5th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int i_prim(int x)
  7. {
  8.     int i;
  9.     for (i=2;i<=sqrt(x);i++)
  10.     if (x%i==0)
  11.     return 0;
  12.     return 1;
  13. }
  14. int diferenta()
  15. {
  16.     int p1,p2,i,n;
  17.     cin>>n;
  18.     if(i_prim(n)==1)
  19.     return 0;
  20.     p1=n-1;
  21.     while (i_prim(p1)==0)
  22.     p1--;
  23.     p2=n+1;
  24.     while (i-prim(p1)==0)
  25.     p2++;
  26.     return p2-p1;
  27. }
  28. int main()
  29. {
  30.  cout<<diferenta();
  31.  return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement