Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int zlozona;
  4. bool pierwszy(int x)
  5. {
  6. if (x==2)
  7. return false;
  8. for (int i=2;i*i<=x;i++)
  9. {
  10. if (x%i==0)
  11. {
  12. return true;
  13. }
  14. }
  15. return false;
  16. }
  17. bool przedzial(int a,int b)
  18. {
  19. for (int j=a;j<=b;j++)
  20. {
  21. if (pierwszy(j)==true)
  22. {
  23. zlozona=j;
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. int main()
  30. {
  31. int ile,a,b;
  32. cin >>ile;
  33. for (int i=0;i<ile;i++)
  34. {
  35. cin >>a>>b;
  36. if(przedzial(a,b)==true)
  37. cout<<zlozona<<"\n";
  38. else
  39. cout<<"NIE\n";
  40. zlozona=0;
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement