Advertisement
NoHatred0

Untitled

Dec 2nd, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /*
  2. Să se determine perechi de numere consecutive care se descompun în produs de două numere
  3. prime distincte, dintr-un interval dat [a,b]. Exemplu: 57,58 cu 57=3*19 si 58=2*29.
  4. */
  5.  
  6. #include <iostream>
  7. #include <math.h>
  8. using namespace std;
  9.  
  10. int prim(int k)
  11. {
  12. int i,ok=1;
  13. for(i=2;i<=sqrt(k);i++)
  14. {
  15. if(k%i==0) ok=0;
  16. }
  17. return ok;
  18. }
  19. int main()
  20. {
  21. int a,b,i,j,k,nr1=0,nr2=0,ok1=0,ok2=0;
  22. cout<<"Dati intervalul:\n a=";cin>>a;
  23. cout<<" b=";cin>>b;
  24. for(i=a;i<b;i++) //parcurg numerele din interval
  25. {
  26. for(j=2;j<=i/2;j++)
  27. {
  28. for(k=2;k<=i/2;k++)
  29. {
  30. if(prim(j)==1 && prim(k)==1 && j*k==i && j!=k && ok1==0) { nr1=i; ok1=1; }
  31. }
  32. }
  33. for(j=2;j<=(i+1)/2;j++)
  34. {
  35. for(k=2;k<=(i+1)/2;k++)
  36. {
  37. if(prim(j)==1 && prim(k)==1 && j*k==(i+1) && j!=k && ok2==0) { nr2=i+1; ok2=1; }
  38. }
  39. }
  40. if(nr2-nr1!=1) {ok1=0;ok2=0;}
  41. }
  42. cout<<nr1<<" "<<nr2<<"\n";
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement