Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n\n";
- }
- void cvv(vector <vector<int>> &v){
- for (auto x: v){
- for (auto y: x){
- cout<<y<<' ';
- }cout<<'\n';
- }cout<<"\n";
- }
- void cb(vector <bool> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n\n";
- }
- vector <vector <int> > gr;
- int n;
- vector <bool> pr;
- vector <int> dv;
- bool gd(int a, int b){
- if ( a < b){
- swap(a,b);
- }
- bool r=0;
- //cout<<"(a/b)= "<<a/b<<'\n';
- //cout<<"(a / b) * b == "<<(a / b) * b<<"\n";
- if ( (a / b) * b == a && pr[a/b] == 1){
- // cout<<"good\n";
- r = 1;
- } else {
- //cout<<"bad\n";
- r = 0;
- }
- return r;
- }
- bool GD(vector <int> &v){
- int sz = v.size();
- bool r = 1;
- if (!gd(v[0], v[sz-1])) r = 0;
- for (int i = 1; i < sz; ++i){
- if (!gd(v[i], v[i-1])){
- r = 0;
- }
- }
- return r;
- }
- void god(vector <int> v){
- cout<<"GO\n";
- int sz = v.size();
- cout<<"sz= "<<v.size()<<"\n";
- bool r = 1;
- if (!gd(v[0], v[sz-1])){
- r = 0;
- cout<<"BAD\n";
- cout<<v[0]<< v[sz-1]<<'\n';
- }
- for (int i = 1; i < sz; ++i){
- cout<<"i= "<<i<<"\n";
- if (!gd(v[i], v[i-1])){
- cout<<"BAD\n";
- r = 0;
- cout<<v[i]<< v[i-1]<<'\n';
- }
- }
- cout<<"r= "<<r<<"\n";
- }
- int main()
- {
- cin>>n;
- pr.resize(n+1, 1);
- for (int i=2; i<=n; ++i){
- for (int j = i*2; j <= n; j += i){
- pr[j] = 0;
- }
- }
- for (int i = 1; i <= n;++i){
- if (n % i == 0) dv.push_back(i);
- }
- gr.resize(dv.size());
- //cv(dv);
- for (int i = 0;i<dv.size();++i){
- for (int j = 0; j != i && j < dv.size(); ++j){
- // cout<<"dv: "<<dv[i]<<' '<<dv[j]<<"\n";
- if (gd(dv[i], dv[j])){
- gr[i].push_back(dv[j]);
- gr[j].push_back(dv[i]);
- }
- }
- }
- /*for (int i = 0;i<gr.size();++i){
- cout<<dv[i]<<": ";
- for (auto x: gr[i]) cout<<x<<' ';
- cout<<"\n";
- }*/
- //cout<<"dv: ";
- //cv(dv);
- set <vector <int> > ptn;
- do {
- //cv(dv);
- vector <int> h;
- for (int i = 0; i < dv.size(); ++i){
- h.push_back(dv[i]);
- ptn.insert(h);
- }
- } while ( next_permutation(dv.begin(), dv.end()) );
- //cout<<"ptn\n";
- //for (auto x: ptn) cv(x);
- int mx_sz = 0;
- vector <int> mx_v;
- for (auto x: ptn){
- //cv(x);
- //cout<<GD(x)<<"\n";
- if ( GD(x) ){
- //cout<<"GD\n";
- //cv(x);
- if (x.size() > mx_sz){
- // cout<<"more\n";
- mx_sz = x.size();
- mx_v = x;
- }
- }
- }
- cout<<mx_sz<<"\n";
- cv(mx_v);
- /*vector <int> l = {1,2,10,5};
- //cout<<GD(l);
- god(l);
- cout<<GD(l);*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement