Advertisement
vlatkovski

Deliteli

Oct 13th, 2017
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define all(cont) cont.begin(), cont.end()
  5.  
  6. inline int stoi(string &s) {
  7.     stringstream ss(s);
  8.     int i;
  9.     ss >> i;
  10.     return i;
  11. }
  12.  
  13. int main() {
  14.     int ncif;
  15.     cin >> ncif;
  16.     string cif = "";
  17.     for (int i = 0; i < ncif; ++i) {
  18.         char x;
  19.         cin >> x;
  20.         cif += x;
  21.     }
  22.     sort(all(cif));
  23.  
  24.     int mind = -1;
  25.     map<int, vector<int>> m;
  26.     do {
  27.         int n = stoi(cif);
  28.         int d = 0;
  29.         for (int i = 1; i <= sqrt(n)+1; ++i) {
  30.             if (n % i == 0) {
  31.                 if (n/i == i) d++;
  32.                 else d += 2;
  33.             }
  34.         }
  35.         m[d].push_back(n);
  36.         if (mind == -1 || d < mind) mind = d;
  37.     } while (next_permutation(all(cif)));
  38.  
  39.     cout << mind << endl;
  40.     sort(all(m[mind]));
  41.     for (int x : m[mind]) cout << x << " ";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement