Advertisement
jakaria_hossain

Toph - largest prime

Oct 2nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fast()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. bool res(int a)
  5. {
  6. if(a==1)return false;
  7. for(int i=2;i<=sqrt(a);i++)
  8. {
  9. if(a%i==0)return false;
  10. }
  11. return true;
  12. }
  13. int main()
  14. {
  15. int n;
  16. scanf("%d",&n);
  17. while(n--)
  18. {
  19. int x,y,i;
  20. scanf("%d %d",&x,&y);
  21. for( i=y;i>=x;i--)
  22. {
  23. if(res(i))
  24. {
  25. printf("%d\n",i);
  26. break;
  27. }
  28. }
  29. if(i==x-1)printf("-1\n");
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement