Advertisement
Farjana_akter

Untitled

Feb 12th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int isprime[100000],psize=0;
  5. bool mark[100000];
  6.  
  7.  
  8. void sieve()
  9. {
  10. int i,j,k;
  11. mark[0]=true;
  12. mark[1]=true;
  13. for(i=0;i*i<=100000;i++)
  14. {
  15. if(mark[i]==false)
  16. {
  17. for(j=i*i;j<=100000;j+=i)
  18. {
  19. mark[j]=true;
  20. }
  21. }
  22. }
  23. psize=0;
  24. for(i=2;i<=100000;i++)
  25. {
  26. if(mark[i]==false)
  27. isprime[psize++]=i;
  28. }
  29. }
  30.  
  31.  
  32.  
  33. int main()
  34. {
  35. sieve();
  36. int n,t,i,j,k;
  37. cin>>t;
  38. while(t--)
  39. {
  40. cin>>n;
  41. int res=0,a=0;
  42. for(i=0;i<psize;i++)
  43. {
  44. if(isprime[i]>n)
  45. break;
  46. else
  47. {
  48. if(a<(n%isprime[i]))
  49. {
  50. res=isprime[i];
  51. a=n%isprime[i];
  52. }
  53. }
  54. }
  55. cout<<res<<endl;
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement