Saleh127

UVA 406.cpp

Jun 15th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. bool a[2000]={true};
  4. int main()
  5. {
  6. int n,i,j,k,l,c,d,e,f;
  7. a[1]=false;
  8. a[0]=true;
  9. for(i=2;i<=2000;i++)
  10. {
  11. if(a[i]==false)
  12. {
  13. for(j=i*i;j<=2000;j+=i)
  14. {
  15. a[j]=true;
  16. }
  17. }
  18. }
  19. while(cin>>n>>c)
  20. {
  21. d=0;
  22. for(i=1;i<=n;i++)
  23. {
  24. if(a[i]==false) d++;
  25. }
  26. e=2*c;
  27. if(d%2) e--;
  28. f=(d-e)/2;
  29. l=0;
  30. cout<<n<<" "<<c<<":";
  31. for(i=1;i<=n;i++)
  32. {
  33. if(a[i]==false)
  34. {
  35. l++;
  36. if(l>(e+f)) break;
  37. if(l>f) cout<<" "<<i;
  38. }
  39. }
  40. cout<<endl<<endl;
  41. }
  42. }
Add Comment
Please, Sign In to add comment