tuki2501

So23_Bai5.cpp

Nov 1st, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 25;
  5.  
  6. int a[N];
  7.  
  8. int pow3(int n) {
  9. int ret = 1;
  10. for (int i = 1; i <= n; i++) {
  11. ret *= 3;
  12. }
  13. return ret;
  14. }
  15.  
  16. int main() {
  17. int m; cin >> m;
  18. int n = 0;
  19. while (m) {
  20. a[n++] = m % 3;
  21. m /= 3;
  22. }
  23. vector<int> l, r;
  24. for (int i = 0; i < n; i++) {
  25. if (a[i] == 2) {
  26. l.push_back(pow3(i));
  27. a[i] = 0;
  28. a[i + 1]++;
  29. }
  30. else if (a[i] == 3) {
  31. a[i] = 0;
  32. a[i + 1]++;
  33. }
  34. }
  35. for (int i = 0; i <= n; i++) {
  36. if (a[i] == 1) {
  37. r.push_back(pow3(i));
  38. }
  39. }
  40. cout << l.size() << ' ';
  41. for (auto &i : l) cout << i << ' ';
  42. cout << '\n';
  43. cout << r.size() << ' ';
  44. for (auto &i : r) cout << i << ' ';
  45. cout << '\n';
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment