fork download
  1. #include "bits/stdc++.h"
  2. #define int long long
  3. using namespace std;
  4.  
  5. vector<int>primes;
  6.  
  7. void solve() {
  8. int n; cin >> n;
  9. int c = n;
  10. map<int,int>cnt;
  11. for(auto p : primes) {
  12. while(c % p == 0) {
  13. cnt[p]++;
  14. c /= p;
  15. }
  16. }
  17.  
  18. if(c != 1)
  19. cnt[c]++;
  20.  
  21. int sum = 0;
  22. for(auto i : cnt)
  23. sum += i.first * i.second;
  24.  
  25. if(sum <= 41) {
  26. int sisa = 41 - sum;
  27. vector<int>ans;
  28. while(sisa--)
  29. ans.push_back(1);
  30. for(auto i : cnt) {
  31. for(int j = 0; j < i.second; ++j)
  32. ans.push_back(i.first);
  33. }
  34.  
  35. cout << ans.size() << " ";
  36. for(auto i : ans) cout << i << " ";
  37. cout << '\n';
  38. } else {
  39. cout << -1 << '\n';
  40. }
  41. }
  42.  
  43. int32_t main() {
  44. ios::sync_with_stdio(false); cin.tie(0);
  45.  
  46. //freopen("sum_41_chapter_1_input.txt", "r", stdin);
  47. //freopen("sum_41_chapter_1_output.txt", "w", stdout);
  48. const int N = 1e6 + 5;
  49. vector<bool>vis(N + 1, 0);
  50. for(int i = 2; i <= N; ++i) {
  51. if(!vis[i]) {
  52. primes.emplace_back(i);
  53. for(int j = i + i; j <= N; j += i) {
  54. vis[j] = 1;
  55. }
  56. }
  57. }
  58.  
  59. int tc; cin >> tc;
  60. for(int T = 1; T <= tc; ++T) {
  61. cout << "Case #" << T << ": ";
  62. solve();
  63. }
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0.01s 5400KB
stdin
1
44
stdout
Case #1: 29 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 11