Sum 41 Chapter 1 Gennady Korotkevich Tourist Source Code
Sum 41 Chapter 1 Gennady Korotkevich Tourist Source Code
* author: tourist
* created: 07.10.2023 13:00:57
**/
#include <bits/stdc++.h>
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int goal = 41;
map<long long, vector<int>> mp;
vector<int> a;
function<void(int, long long, int)> Dfs = [&](int s, long long p, int v) {
if (s == goal) {
if (mp.find(p) == mp.end() || a.size() < mp[p].size()) {
mp[p] = a;
}
return;
}
for (int i = v; i + s <= goal; i++) {
a.push_back(i);
Dfs(s + i, p * i, i);
a.pop_back();
}
};
Dfs(0, 1, 1);
int tt;
cin >> tt;
for (int qq = 1; qq <= tt; qq++) {
cout << "Case #" << qq << ": ";
long long p;
cin >> p;
if (mp.find(p) == mp.end()) {
cout << -1 << '\n';
} else {
auto res = mp[p];
cout << res.size();
for (int x : res) {
cout << " " << x;
}
cout << '\n';
}
}
return 0;
}