Saleh127

uva 10852.cpp

Jun 7th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define pi acos(-1)
  7. #define yes printf("YES\n");
  8. #define no printf("NO\n");
  9. #define maX 10008
  10. bool marked[maX];
  11. void sieve()
  12. {
  13. marked[0]=1;
  14. marked[1]=1;
  15. for(int i=4;i<=maX;i+=2)
  16. {
  17. marked[i]=1;
  18. }
  19. for(int i=3;i<=maX;i+=2)
  20. {
  21. if(marked[i]==0)
  22. {
  23. for(int j=i*i; j<=maX; j+=i+i)
  24. {
  25. marked[j]=1;
  26. }
  27. }
  28. }
  29. }
  30. int main()
  31. {
  32. Faster
  33. sieve();
  34. test
  35. {
  36. int a,c,d,i,j,k,l;
  37. cin>>a;
  38. for(i=a/2+1;i<=maX;i++)
  39. {
  40. if(marked[i]==0)
  41. {
  42. printf("%d\n",i);
  43. break;
  44. }
  45. }
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment