fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define v(x) vector<x>
  12. #define nl '\n'
  13. #define fxd(x) fixed << setprecision(x)
  14. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  15. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17. // pow|base
  18. vector<ll> primefactors(ll n)
  19. {
  20. vector<ll> res;
  21. for (int i = 2; i*i <= n; i++)
  22. {
  23.  
  24. while (n%i == 0)
  25. {
  26.  
  27. res.push_back(i);
  28. n /= i;
  29. }
  30. }
  31. if(n > 1) res.push_back(n);
  32. return res;
  33. }
  34.  
  35. int main()
  36. {
  37. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  38. ll n , k; cin >> n >> k;
  39. vector<ll> pm = primefactors(n);
  40.  
  41. if(pm.size() < k)
  42. {
  43. cout << -1;
  44. }
  45. else
  46. {
  47. for (int i = 0; i < k-1; i++)
  48. {
  49. cout << pm[i] << " ";
  50. }
  51. ll res = 1;
  52. for (int i = k-1; i < pm.size(); i++)
  53. {
  54. res *= pm[i];
  55. }
  56. cout << res;
  57.  
  58. }
  59. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
-1