Advertisement
Guest User

Промежуточное

a guest
May 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using namespace std;
  2.  
  3. #include <algorithm>
  4. #include <map>
  5.  
  6. #ifdef DEBUG
  7. #include <fstream>
  8. ifstream IN("input.txt");
  9. ofstream OUT("output.txt");
  10. #endif
  11.  
  12. #ifndef DEBUG
  13. #include <iostream>
  14. #define IN cin
  15. #define OUT cout
  16. #endif
  17.  
  18. map<int, bool> pr;
  19. map<int, bool> prs;
  20. map<int, pair<int, int>> nxt;
  21.  
  22. int n;
  23.  
  24. int main() {
  25. ios_base::sync_with_stdio(0);
  26. IN >> n;
  27. int x;
  28. int max = 0;
  29. int chkd = 3;
  30. prs[2] = true;
  31. for (int i = 0; i < n; ++i) {
  32. IN >> x;
  33. if (pr[x]) {
  34. while (pr[x]) {
  35. OUT << nxt[x].first << " ";
  36. x = nxt[x].second;
  37. }
  38. if (x > 1) {
  39. OUT << x;
  40. }
  41. OUT << endl;
  42. }
  43. else if (prs[x]) OUT << x << endl;
  44. else {
  45. while (!(x % 2)) {
  46. OUT << "2 ";
  47. pr[x] = true;
  48. int y = x / 2;
  49. nxt[x] = { 2, x / 2 };
  50. x = y;
  51. }
  52. int sx = x;
  53. while (!pr[x] && !prs[x]) {
  54. bool f = false;
  55. int j = 3;
  56. while ((j <= sqrt(x) && !f)) {
  57. if (!(x % j)) {
  58. prs[j] = true;
  59. f = true;
  60. pr[x] = true;
  61. int y = x / j;
  62. nxt[x] = { j, y };
  63. OUT << j << " ";
  64. x = y;
  65. }
  66. j += 2;
  67. }
  68. if (!f) {
  69. prs[x] = true;
  70. }
  71. }
  72. while (pr[x]) {
  73. OUT << nxt[x].first << " ";
  74. x = nxt[x].second;
  75. }
  76. if (x > 1) {
  77. OUT << x;
  78. }
  79. OUT << endl;
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement