Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4. ifstream fin("numere23.in");
  5. ofstream fout("numere23.out");
  6.  
  7. int prim3(int n)
  8. {
  9. if(n == 1)
  10. return 0;
  11. int e, cnt = 0;
  12. for(int d = 2;d <= n;d++)
  13. {
  14. e = 0;
  15. while(n % d == 0)
  16. {
  17. e++;
  18. n /= d;
  19. }
  20. if(e > 0)
  21. cnt++;
  22. }
  23. if(cnt <= 3)
  24. return 1;
  25. else
  26. return 0;
  27. }
  28.  
  29. int main()
  30. {
  31. int n, k, c, pr3[10100], j = 2, i = 0, maxim = -1, q, cnt = 2, poz = 1, sol[10100], f[10100], rest;
  32. fin >> n >> k >> c;
  33. if(c == 1)
  34. {
  35. while(i <= n)
  36. {
  37. if(prim3(j) == 1)
  38. pr3[++i] = j;
  39. j++;
  40. }
  41. for(q = 1;q <= n;q++)
  42. maxim = max(pr3[q], maxim);
  43. fout << maxim;
  44. }
  45. else if(c == 2)
  46. {
  47. while(i <= n)
  48. {
  49. if(prim3(j) == 1)
  50. pr3[++i] = j;
  51. j++;
  52. }
  53. q = 1;
  54. poz = 1;
  55. sol[1] = pr3[1];
  56. f[pr3[1]]++;
  57. rest = 0;
  58.  
  59. while(cnt <= n)
  60. {
  61. poz += k;
  62. if(poz > n)
  63. poz = poz % n;
  64. if(sol[poz] == 0)
  65. {
  66. sol[poz] = pr3[++q];
  67. cnt++;
  68. }
  69. else
  70. {
  71. while(sol[poz] != 0)
  72. {
  73. poz++;
  74. if(poz > n)
  75. poz = poz % n;
  76. }
  77. }
  78. for(i = poz;i <= n;i++)
  79. {
  80. if(sol[i] != 0)
  81. poz++;
  82. if(poz > n)
  83. poz = poz % n;
  84. }
  85.  
  86.  
  87. }
  88. for(q = 1;q <= n;q++)
  89. fout << sol[q] << " ";
  90.  
  91. }
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement