Advertisement
Korotkodul

Division Circle. Innopolis

Dec 11th, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #define pii pair <int,int>
  10. using namespace std;
  11. using ll = long long;
  12. void cv(vector <int> &v){
  13. for (auto x: v) cout<<x<<' ';
  14. cout<<"\n\n";
  15. }
  16.  
  17. void cvv(vector <vector<int>> &v){
  18. for (auto x: v){
  19. for (auto y: x){
  20. cout<<y<<' ';
  21. }cout<<'\n';
  22. }cout<<"\n";
  23. }
  24.  
  25. void cb(vector <bool> &v){
  26. for (auto x: v) cout<<x<<' ';
  27. cout<<"\n\n";
  28. }
  29. vector <vector <int> > gr;
  30.  
  31. int n;
  32. vector <bool> pr;
  33. vector <int> dv;
  34. bool gd(int a, int b){
  35. if ( a < b){
  36. swap(a,b);
  37. }
  38. bool r=0;
  39. //cout<<"(a/b)= "<<a/b<<'\n';
  40. //cout<<"(a / b) * b == "<<(a / b) * b<<"\n";
  41. if ( (a / b) * b == a && pr[a/b] == 1){
  42. // cout<<"good\n";
  43. r = 1;
  44. } else {
  45. //cout<<"bad\n";
  46. r = 0;
  47. }
  48. return r;
  49. }
  50.  
  51.  
  52. bool GD(vector <int> &v){
  53. int sz = v.size();
  54. bool r = 1;
  55. if (!gd(v[0], v[sz-1])) r = 0;
  56. for (int i = 1; i < sz; ++i){
  57. if (!gd(v[i], v[i-1])){
  58. r = 0;
  59. }
  60. }
  61. return r;
  62. }
  63.  
  64. void god(vector <int> v){
  65. cout<<"GO\n";
  66. int sz = v.size();
  67. cout<<"sz= "<<v.size()<<"\n";
  68. bool r = 1;
  69. if (!gd(v[0], v[sz-1])){
  70. r = 0;
  71. cout<<"BAD\n";
  72. cout<<v[0]<< v[sz-1]<<'\n';
  73. }
  74. for (int i = 1; i < sz; ++i){
  75. cout<<"i= "<<i<<"\n";
  76. if (!gd(v[i], v[i-1])){
  77. cout<<"BAD\n";
  78. r = 0;
  79. cout<<v[i]<< v[i-1]<<'\n';
  80. }
  81. }
  82. cout<<"r= "<<r<<"\n";
  83. }
  84.  
  85. int main()
  86. {
  87. cin>>n;
  88. pr.resize(n+1, 1);
  89. for (int i=2; i<=n; ++i){
  90. for (int j = i*2; j <= n; j += i){
  91. pr[j] = 0;
  92. }
  93. }
  94. for (int i = 1; i <= n;++i){
  95. if (n % i == 0) dv.push_back(i);
  96. }
  97. gr.resize(dv.size());
  98. //cv(dv);
  99. for (int i = 0;i<dv.size();++i){
  100. for (int j = 0; j != i && j < dv.size(); ++j){
  101. // cout<<"dv: "<<dv[i]<<' '<<dv[j]<<"\n";
  102. if (gd(dv[i], dv[j])){
  103. gr[i].push_back(dv[j]);
  104. gr[j].push_back(dv[i]);
  105. }
  106. }
  107. }
  108. /*for (int i = 0;i<gr.size();++i){
  109. cout<<dv[i]<<": ";
  110. for (auto x: gr[i]) cout<<x<<' ';
  111. cout<<"\n";
  112. }*/
  113. //cout<<"dv: ";
  114. //cv(dv);
  115. set <vector <int> > ptn;
  116.  
  117. do {
  118. //cv(dv);
  119. vector <int> h;
  120. for (int i = 0; i < dv.size(); ++i){
  121. h.push_back(dv[i]);
  122. ptn.insert(h);
  123. }
  124. } while ( next_permutation(dv.begin(), dv.end()) );
  125. //cout<<"ptn\n";
  126. //for (auto x: ptn) cv(x);
  127. int mx_sz = 0;
  128. vector <int> mx_v;
  129. for (auto x: ptn){
  130. //cv(x);
  131. //cout<<GD(x)<<"\n";
  132. if ( GD(x) ){
  133. //cout<<"GD\n";
  134. //cv(x);
  135. if (x.size() > mx_sz){
  136. // cout<<"more\n";
  137. mx_sz = x.size();
  138. mx_v = x;
  139. }
  140. }
  141. }
  142. cout<<mx_sz<<"\n";
  143. cv(mx_v);
  144. /*vector <int> l = {1,2,10,5};
  145. //cout<<GD(l);
  146. god(l);
  147. cout<<GD(l);*/
  148. }
  149.  
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement