Advertisement
erfanul007

UVa 406

Mar 14th, 2019
148
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. bool chk[1009];
  5. int total[1009];
  6. vector< int > prime;
  7.  
  8. void seive()
  9. {
  10. memset(chk,0,sizeof(chk));
  11. chk[0]=1;
  12. chk[1]=0;
  13. prime.push_back(1);
  14. for(int i=2;i<=1000;i++){
  15. if(chk[i]){
  16. continue;
  17. }
  18. prime.push_back(i);
  19. for(int j=2;i*j<=1000;j++){
  20. chk[i*j]=1;
  21. }
  22. }
  23. int cnt=0;
  24. for(int i=1;i<=1000;i++){
  25. if(chk[i]==0){
  26. cnt++;
  27. }
  28. total[i]=cnt;
  29. }
  30. }
  31.  
  32. int main()
  33. {
  34. seive();
  35. int n,c,i,j;
  36. while(cin>>n>>c){
  37. cout<<n<<" "<<c<<":";
  38. int sum = total[n];
  39. int x = sum/2;
  40. if(sum%2==0){
  41. i = x-c;
  42. j = x-1+c;
  43. }
  44. else{
  45. i = x-c+1;
  46. j= x-1+c;
  47. }
  48. if(i<0) i=0;
  49. if(j>=sum) j=sum-1;
  50. for(int z=i;z<=j;z++){
  51. cout<<" "<<prime[z];
  52. }
  53. cout<<"\n\n";
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement