fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define nl "\n"
  5. #define OO 0x3f3f3f3f
  6. const ll dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
  7. const ll dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
  8. const ll dir[] = {0, 1, 2, 3};
  9. using namespace std;
  10. void ta2to2a()
  11. {
  12. ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);
  13. if (fopen("input.txt", "r"))
  14. {
  15. freopen("input.txt", "r", stdin);
  16. freopen("output.txt", "w", stdout);
  17. }
  18. }
  19. map<ll,ll>m;
  20. map<ll,vector<ll>>mp;
  21. void divisors(ll n)
  22. {
  23. for (ll i=1; i*i<=n; i++)
  24. {
  25. while (n%i==0 && m[i])
  26. {
  27. mp[n].push_back(i);
  28. m[i]--;
  29. }
  30. while (m[n/i] && n%i==0)
  31. {
  32. mp[n].push_back(n/i);
  33. m[n/i]--;
  34. }
  35. }
  36. }
  37. int main()
  38. {
  39. ta2to2a();
  40. ll n;
  41. cin >> n;
  42. vector<ll> a(n);
  43. for (ll i = 0; i < n; i++)
  44. {
  45. cin >> a[i];
  46. m[a[i]]++;
  47. }
  48. sort(a.begin(), a.end());
  49. for (ll i=n-1; i>=0; i--)
  50. {
  51. if (m[a[i]])divisors(a[i]);
  52. }
  53. cout<<mp.size()<<endl;
  54. for (auto i : mp)
  55. {
  56. cout<<i.second.size()<<" ";
  57. for (auto j : i.second)
  58. {
  59. cout<<j<<" ";
  60. }
  61. cout<<endl;
  62. }
  63. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
0