Advertisement
a53

Numere23

a53
Jan 29th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <fstream>
  2. #define NN 20005
  3. using namespace std;
  4. ifstream f("numere23.in");
  5. ofstream g("numere23.out");
  6. int n,k,c,poz=1,nr;
  7. int sol[NN];
  8. char ciur[NN],ciur3[NN];
  9.  
  10. int main()
  11. {
  12. int i,j,i2;
  13. f>>n>>k>>c;
  14. for(i=2;i<NN;++i)
  15. ciur[i]=1;
  16. for(i=2;i<=NN;++i)
  17. if(ciur[i])
  18. for(j=2;j*i<NN;++j)
  19. ciur[i*j]=0;
  20. for(i=2;i<=NN;++i)
  21. ciur3[i]=ciur[i];
  22. for(i=2;i<NN;++i)
  23. for(j=i;j*i<NN;++j)
  24. if(ciur[i]==1&&ciur[j]==1)
  25. ciur3[i*j]=1;
  26. for(i=2;i<NN;++i)
  27. for(j=i;j*i<NN;++j)
  28. for(i2=j;i2*j*i<NN;++i2)
  29. if(ciur[i]==1&&ciur[j]==1&&ciur[i2]==1)
  30. ciur3[i*j*i2]=1;
  31. if(c==1)
  32. {
  33. for(i=2,j=0;j<n;++i)
  34. if(ciur3[i]==1)
  35. ++j;
  36. g<<i-1<<'\n';
  37. return 0;
  38. }
  39. for(i=2;nr<n;++i)
  40. if(ciur3[i])
  41. {
  42. sol[poz]=i;
  43. ++nr;
  44. if(nr<n)
  45. for(i2=1;i2<=k;++i2)
  46. {
  47. ++poz;
  48. if(poz>n)
  49. poz=1;
  50. while(sol[poz])
  51. if(poz<n)
  52. ++poz;
  53. else
  54. poz=1;
  55. }
  56. }
  57. for(i=1;i<=n;++i)
  58. g<<sol[i]<<' ';
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement